1Heap::Elem::Ref(3)    User Contributed Perl Documentation   Heap::Elem::Ref(3)
2
3
4

NAME

6       Heap::Elem::Ref - Object Reference Heap Elements
7

SYNOPSIS

9         use Heap::Elem::Ref( RefElem );
10         use Heap::Fibonacci;
11
12         my $heap = Heap::Fibonacci->new;
13         my $elem;
14
15         foreach $i ( 1..100 ) {
16             $obj = myObject->new( $i );
17             $elem = RefElem( $obj );
18             $heap->add( $elem );
19         }
20
21         while( defined( $elem = $heap->extract_top ) ) {
22             # assume that myObject object have a method I<printable>
23             print "Smallest is ", $elem->val->printable, "\n";
24         }
25

DESCRIPTION

27       Heap::Elem::Ref is used to wrap object reference values into an element
28       that can be managed on a heap.  Each referenced object must have a
29       method cmp which can compare itself with any of the other objects that
30       have references on the same heap.  These comparisons must be consistant
31       with normal arithmetic.  The top of the heap will have the smallest
32       (according to cmp) element still remaining.  (See Heap::Elem::RefRev if
33       you want the heap to always return the largest element.)
34
35       The details of the Elem interface are described in Heap::Elem.
36
37       The details of using a Heap interface are described in Heap.
38

AUTHOR

40       John Macdonald, john@perlwolf.com
41
43       Copyright 1998-2007, O'Reilly & Associates.
44
45       This code is distributed under the same copyright terms as perl itself.
46

SEE ALSO

48       Heap(3), Heap::Elem(3), Heap::Elem::RefRev(3).
49
50
51
52perl v5.36.0                      2023-01-20                Heap::Elem::Ref(3)
Impressum