Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / Heap / Elem / NumRev.pm
CommitLineData
86530b38
AT
1package Heap::Elem::NumRev;
2
3use strict;
4use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
5
6require Exporter;
7require AutoLoader;
8
9@ISA = qw(Exporter AutoLoader);
10
11# No names exported.
12@EXPORT = ( );
13
14# Available for export: NumRElem (to allocate a new Heap::Elem::NumRev value)
15@EXPORT_OK = qw( NumRElem );
16
17$VERSION = '0.70';
18
19
20# Preloaded methods go here.
21
22sub new {
23 my $class = shift;
24 $class = ref($class) || $class;
25
26 # two slot array, 0 for the numeric value, 1 for use by Heap
27 my $self = [ shift, undef ];
28
29 return bless $self, $class;
30}
31
32sub NumRElem { # exportable synonym for new
33 Heap::Elem::NumRev->new(@_);
34}
35
36# get or set value slot
37sub val {
38 my $self = shift;
39 @_ ? ($self->[0] = shift) : $self->[0];
40}
41
42# get or set heap slot
43sub heap {
44 my $self = shift;
45 @_ ? ($self->[1] = shift) : $self->[1];
46}
47
48# compare two NumR elems (reverse order)
49sub cmp {
50 my $self = shift;
51 my $other = shift;
52 return $other->[0] <=> $self->[0];
53}
54
55# Autoload methods go after =cut, and are processed by the autosplit program.
56
571;
58__END__
59# Below is the stub of documentation for your module. You better edit it!
60
61=head1 NAME
62
63Heap::Elem::NumRev - Perl extension for Reversed Numeric Heap Elements
64
65=head1 SYNOPSIS
66
67 use Heap::Elem::NumRev( NumRElem );
68 use Heap::Fibonacci;
69
70 my $heap = Heap::Fibonacci->new;
71 my $elem;
72
73 foreach $i ( 1..100 ) {
74 $elem = NumRElem( $i );
75 $heap->add( $elem );
76 }
77
78 while( defined( $elem = $heap->extract_top ) ) {
79 print "Largest is ", $elem->val, "\n";
80 }
81
82=head1 DESCRIPTION
83
84Heap::Elem::NumRev is used to wrap numeric values into an element
85that can be managed on a heap. The top of the heap will have
86the largest element still remaining. (See L<Heap::Elem::Num>
87if you want the heap to always return the smallest element.)
88
89The details of the Elem interface are described in L<Heap::Elem>.
90
91The details of using a Heap interface are described in L<Heap>.
92
93=head1 AUTHOR
94
95John Macdonald, jmm@perlwolf.com
96
97=head1 COPYRIGHT
98
99Copyright 1998-2003, O'Reilly & Associates.
100
101This code is distributed under the same copyright terms as perl itself.
102
103=head1 SEE ALSO
104
105Heap(3), Heap::Elem(3), Heap::Elem::Num(3).
106
107=cut