Algorithm::SlidingWindow::Dynamic

CI MetaCPAN

Generic, dynamically sized sliding window.

This module implements a count-based sliding window (deque) over arbitrary Perl scalars. It supports growing and shrinking from either end and a slide() operation for fixed-length rolling windows.

Install

From CPAN (recommended)

cpanm Algorithm::SlidingWindow::Dynamic

From source (this repo)

perl Makefile.PL
make
make test
make install

Synopsis

use Algorithm::SlidingWindow::Dynamic;

my $w = Algorithm::SlidingWindow::Dynamic->new;

$w->push(1, 2, 3);        # window: 1 2 3
my $a = $w->shift;        # removes 1, window: 2 3
my $b = $w->pop;          # removes 3, window: 2

$w->push(qw(a b c));      # window: 2 a b c
my $ev = $w->slide('d');  # evicts 2, window: a b c d

my @vals = $w->values;    # (a, b, c, d)

Documentation

Full documentation is in the module POD:

Source Code

License

Same terms as Perl itself. See LICENSE.