1package Heap::Elem::RefRev;
2
3use strict;
4use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
5use Heap::Elem;
6
7require Exporter;
8
9@ISA = qw(Exporter Heap::Elem);
10
11# No names exported.
12@EXPORT = ( );
13
14# Available for export: RefRElem (to allocate a new Heap::Elem::RefRev value)
15@EXPORT_OK = qw( RefRElem );
16
17$VERSION = '0.80';
18
19sub RefRElem {	# exportable synonym for new
20    Heap::Elem::RefRev->new(@_);
21}
22
23# compare two RefRev elems - the objects must have a compatible cmp method
24sub cmp {
25    return $_[1][0]->cmp( $_[0][0] );
26}
27
281;
29__END__
30
31=head1 NAME
32
33Heap::Elem::RefRev - Reversed Object Reverence Heap Elements
34
35=head1 SYNOPSIS
36
37  use Heap::Elem::RefRev( RefRElem );
38  use Heap::Fibonacci;
39
40  my $heap = Heap::Fibonacci->new;
41  my $elem;
42
43  foreach $i ( 1..100 ) {
44      $obj = myObject->new( $i );
45      $elem = RefRElem( $obj );
46      $heap->add( $elem );
47  }
48
49  while( defined( $elem = $heap->extract_top ) ) {
50      # assume that myObject object have a method I<printable>
51      print "Largest is ", $elem->val->printable, "\n";
52  }
53
54=head1 DESCRIPTION
55
56Heap::Elem::RefRev is used to wrap object reference values into an
57element that can be managed on a heap.  Each referenced object must
58have a method I<cmp> which can compare itself with any of the other
59objects that have references on the same heap.  These comparisons
60must be consistant with normal arithmetic.  The top of the heap will
61have the largest (according to I<cmp>) element still remaining.
62(See L<Heap::Elem::Ref> if you want the heap to always return the
63smallest element.)
64
65The details of the Elem interface are described in L<Heap::Elem>.
66
67The details of using a Heap interface are described in L<Heap>.
68
69=head1 AUTHOR
70
71John Macdonald, john@perlwolf.com
72
73=head1 COPYRIGHT
74
75Copyright 1998-2007, O'Reilly & Associates.
76
77This code is distributed under the same copyright terms as perl itself.
78
79=head1 SEE ALSO
80
81Heap(3), Heap::Elem(3), Heap::Elem::Ref(3).
82
83=cut
84