NAME
Array::FIFO - A Simple limitable FIFO array, with some convenience methods to crunch the data
VERSION
version 0.07
SYNOPSIS
my $ar = Array::FIFO->new( limit => 12 );
$ar->add( 20 );
$ar->add( 18 );
$ar->add( 22 );
say $ar->average;
DESCRIPTION
Array::FIFO is meant to be a simple limitable FIFO array, for storing data in a FIFO manner, with an optional limit to how large the array can get. When the limit is reached, the oldest value is discarded when new values are added.
It's intent is for numeric values (i.e. current load of a system), but it should work for other data types.
The sum
and average
methods keep the current sum and average of the numbers as you would expect. It does this on demand.
METHODS
new
limit
(optional)-
Numeric value of how large the array is allowed to get. When it reaches limit, every item added causes the oldest item to be removed.
If no value is passed, there is no max size.
add
$ar->add( 99 );
You can add any type of item to the array; if it's not a number it will just not affect the sum() or average() calculations.
remove
$ar->remove;
Remove the oldest item on the array.
queue
$ar->queue;
Reference directly the fifo array.
size
$ar->size;
How many elements are in the array.
limit
$ar->limit;
The maximum size the array is allow to be.
sum
$ar->sum;
The sum of all numeric elements in the array.
average
$ar->average;
The average of all numeric elements in the array.
AUTHOR
Dan Burke dburke at addictmud.org
BUGS
If you encounter any bugs, or have feature requests, please create an issue on github. https://github.com/dwburke/perl-Array-FIFO/issues