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