Data::RingBuffer - A simple ring buffer data structure
use Data::RingBuffer; my $rb = Data::RingBuffer->new(4); $rb->push($obj1); $rb->push($obj2); $rb->push($obj3); $obj1 = $rb->get(); $obj2 = $rb->get(); $rb->push($obj4); $rb->push($obj5); # $obj1 removed from the buffer $obj3 = $rb->get(); my $objs = $rb->getall(); # [ $obj2, $obj3, $obj4, $obj5 ]
Ring buffer data structure could be used in a various environments, demanding circular data storage or any kind of cyclic data caching. There is a good implementation of arrays in Perl, which supports elements addition in any direction. This module provides a simple wrapper over them.
$obj = Data::RingBuffer->new($size) is an object constructor that will correctly initialize the object being created.
$obj = Data::RingBuffer->new($size)
$size
Add an $element to the buffer.
$element
Get next $element from the buffer.
Get an arrayref of all the elements in the buffer.
Sergei Zhmylev, <zhmylove@cpan.org>
<zhmylove@cpan.org>
Please report any bugs or feature requests to official GitHub page at https://github.com/zhmylove/data-ringbuffer. You also can use official CPAN bugtracker by reporting to bug-data-ringbuffer at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-RingBuffer. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-data-ringbuffer at rt.cpan.org
To install this module, run the following commands:
$ perl Makefile.PL $ make $ make test $ make install
This software is Copyright (c) 2020 by Sergei Zhmylev.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Data::RingBuffer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::RingBuffer
CPAN shell
perl -MCPAN -e shell install Data::RingBuffer
For more information on module installation, please visit the detailed CPAN module installation guide.