/usr/share/perl5/Heap.pm is in libheap-perl 0.80-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | package Heap;
# heap is mainly here as documentation for the common heap interface.
# It defaults to Heap::Fibonacci.
use strict;
use vars qw($VERSION);
$VERSION = '0.80';
sub new {
use Heap::Fibonacci;
return &Heap::Fibonacci::new;
}
1;
__END__
=head1 NAME
Heap - Perl extensions for keeping data partially sorted
=head1 SYNOPSIS
use Heap;
my $heap = Heap->new;
my $elem;
use Heap::Elem::Num(NumElem);
foreach $i ( 1..100 ) {
$elem = NumElem( $i );
$heap->add( $elem );
}
while( defined( $elem = $heap->extract_top ) ) {
print "Smallest is ", $elem->val, "\n";
}
=head1 DESCRIPTION
The Heap collection of modules provide routines that manage
a heap of elements. A heap is a partially sorted structure
that is always able to easily extract the smallest of the
elements in the structure (or the largest if a reversed compare
routine is provided).
If the collection of elements is changing dynamically, the
heap has less overhead than keeping the collection fully
sorted.
The elements must be objects as described in L<"Heap::Elem">
and all elements inserted into one heap must be mutually
compatible - either the same class exactly or else classes that
differ only in ways unrelated to the B<Heap::Elem> interface.
=head1 METHODS
=over 4
=item $heap = HeapClass::new(); $heap2 = $heap1->new();
Returns a new heap object of the specified (sub-)class.
This is often used as a subroutine instead of a method,
of course.
=item $heap->DESTROY
Ensures that no internal circular data references remain.
Some variants of Heap ignore this (they have no such references).
Heap users normally need not worry about it, DESTROY is automatically
invoked when the heap reference goes out of scope.
=item $heap->add($elem)
Add an element to the heap.
=item $elem = $heap->top
Return the top element on the heap. It is B<not> removed from
the heap but will remain at the top. It will be the smallest
element on the heap (unless a reversed cmp function is being
used, in which case it will be the largest). Returns I<undef>
if the heap is empty.
This method used to be called "minimum" instead of "top". The
old name is still supported but is deprecated. (It was confusing
to use the method "minimum" to get the maximum value on the heap
when a reversed cmp function was used for ordering elements.)
=item $elem = $heap->extract_top
Delete the top element from the heap and return it. Returns
I<undef> if the heap was empty.
This method used to be called "extract_minimum" instead of
"extract_top". The old name is still supported but is deprecated.
(It was confusing to use the method "extract_minimum" to get the
maximum value on the heap when a reversed cmp function was used
for ordering elements.)
=item $heap1->absorb($heap2)
Merge all of the elements from I<$heap2> into I<$heap1>.
This will leave I<$heap2> empty.
=item $heap1->decrease_key($elem)
The element will be moved closed to the top of the
heap if it is now smaller than any higher parent elements.
The user must have changed the value of I<$elem> before
I<decrease_key> is called. Only a decrease is permitted.
(This is a decrease according to the I<cmp> function - if it
is a reversed order comparison, then you are only permitted
to increase the value of the element. To be pedantic, you
may only use I<decrease_key> if
I<$elem->cmp($elem_original) <= 0> if I<$elem_original> were
an elem with the value that I<$elem> had before it was
I<decreased>.)
=item $elem = $heap->delete($elem)
The element is removed from the heap (whether it is at
the top or not).
=back
=head1 AUTHOR
John Macdonald, john@perlwolf.com
=head1 COPYRIGHT
Copyright 1998-2007, O'Reilly & Associates.
This code is distributed under the same copyright terms as perl itself.
=head1 SEE ALSO
Heap::Elem(3), Heap::Binary(3), Heap::Binomial(3), Heap::Fibonacci(3).
=cut
|