This is an implementation of a Min-Max Binary Heap, based on 1986 article
"Min-Max Heaps and Generalized Priority Queues" by Atkinson, Sack,
Santoro, and Strothotte, published in Communications of the ACM.
In a Min-Max heap, objects are stored in partial order such that both the
minimum element and maximum element are available in constant time. This
is accomplished through a modification of the standard heap algorithm that
introduces the notion of 'min' (even) levels and 'max' (odd) levels in the
binary tree structure of the heap.
With a Min-Max heap you get all this, plus insertion into a Min-Max heap is
actually *faster* than with a normal heap (by a constant factor of 0.5).
For further information about the algorithm, please see the article "Min-Max
Heaps and Generalized Priority Queues" by Atkinson, Sack, Santoro, and
Strothotte, published in Communications of the ACM in 1986.
################################################################
#
# Example 1
#
# shows basic (default constructor) behavior of heap.
# the default comparison function is numeric.
#
################################################################
################################################################
#
# Example 2
#
# shows how you can store any set of comparable objects in heap.
#
#
# Note: in this example, anonymous subroutines are
# passed in to the constructor, but you can just as well supply
# your own object's comparison methods by name- i.e.,
#
# $avltree = Heap::MinMax->new(
# fcompare => \&MyObj::compare,
#
# . . .
#
# etc...
#
################################################################
use Heap::MinMax;
my $elt1 = { _name => "Bob",
_phone => "444-4444",};
my $elt2 = { _name => "Amy",
_phone => "555-5555",};
my $elt3 = { _name => "Sara",
_phone => "666-6666",};
This module requires these other modules and libraries:
none.
COPYRIGHT AND LICENCE
Copyright (C) 2009 by Matthias Beebe
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.8 or,
at your option, any later version of Perl 5 you may have available.