Lukas Mai > Data-PrioQ-SkewBinomial-0.03 > Data::PrioQ::SkewBinomial



Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  


Data::PrioQ::SkewBinomial - A functional priority queue based on skew binomial trees


    use aliased 'Data::PrioQ::SkewBinomial' => 'PQ';
    my $pq = PQ->empty;
    $pq = $pq->insert(1, "foo")->insert(3, "baz")->insert(2, "bar");
    until ($pq->is_empty) {
        ($pq, my ($priority, $data)) = $pq->shift_min;
        print "$priority: $data\n";


This module provides a purely functional priority queue. "Purely functional" means no method ever modifies a queue; instead they all return a new modified object. There is no real constructor either because there's no need for one: if the empty queue is never modified, you can just reuse it.

The following methods are available:


O(1). Returns the empty queue.


O(1). Tests whether a priority queue is empty. Returns a boolean value.

$pq->insert($priority, $item)

O(1). Returns a new queue containing $item inserted into $pq with a priority level of $priority. $priority must be a number.


O(1). Returns a new queue containing all elements of $pq and $pq2.


O(1). Finds the item with the lowest priority value in $pq. Returns ($priority, $item) in list context and $item in scalar context. If $pq is empty, returns the empty list/undef.


O(log n). Finds and removes the item with the lowest priority value in $pq. Returns ($pq_, $priority, $item) in list context and $pq_ in scalar context, where $pq_ is a priority queue containing the remaining elements. If $pq is empty, returns ($pq, undef, undef)/$pq in list/scalar context, respectively.


Lukas Mai, <l.mai at>


Please report any bugs or feature requests to bug-data-prioq-skewbinomial at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Data::PrioQ::SkewBinomial

You can also look for information at:


The code in this module is based on: Chris Okasaki, Purely Functional Data Structures.


Copyright 2008 Lukas Mai, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: