GithubHelp home page GithubHelp logo

perl-array-queue-priority's Introduction

NAME

Array::Queue::Priority - A custom sorted queue

VERSION

version 0.1.2

SYNOPSIS

my $queue = Array::Queue::Priority->new(
    sort_cb => sub {
        $_[0]->{last_name} cmp $_[1]->{last_name}
    });
$ar->add({ last_name => 'Rogers' });
$ar->add({ last_name => 'Stark' });
$ar->add({ last_name => 'Banner' });

while ($node = $queue->first) {
    # do things with node
    $queue->remove;
}

DESCRIPTION

Array::Queue::Priority priority queue, sorted by whatever you desire.

As values are inserted, they are sorted on the fly, ensuring the values come out in the order you desire. You simply supply the sort_cb at the time of construction.

If no sort_cb is supplied, it will try to sort by values passed. You'll probably get warnings if that's just a string, and who knows what you will get if it's a hashref. Straight numbers will work just find though.

Call first() then remove() for a little "transactional safety" if there's an error processing the first item in the queue.

Inherits from Array::Queue.

METHODS

add

$ar->add( 99 );

You can add any type of item to the queue.

remove

$ar->remove;

Remove the oldest item on the queue.

Returns value removed.

first

$ar->first;

Returns the first / oldest item in the queue.

Leaves the item in the queue.

queue

$ar->queue;

Reference directly the array used to store the queued items.

size

$ar->size;

How many elements are in the queue.

empty

$ar->empty;

Boolean, is queue empty?

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-Queue/issues

Pull requests also welcome.

LICENSE AND COPYRIGHT

http://www.perlfoundation.org/artistic_license_2_0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.