1package Heap::Elem::Str; 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: StrElem (to allocate a new Heap::Elem::Str value) 15@EXPORT_OK = qw( StrElem ); 16 17$VERSION = '0.80'; 18 19sub StrElem { # exportable synonym for new 20 Heap::Elem::Str->new(@_); 21} 22 23# compare two Str elems 24sub cmp { 25 my $self = shift; 26 my $other = shift; 27 return $_[0][0] cmp $_[1][0]; 28} 29 301; 31__END__ 32 33=head1 NAME 34 35Heap::Elem::Str - String Heap Elements 36 37=head1 SYNOPSIS 38 39 use Heap::Elem::Str( StrElem ); 40 use Heap::Fibonacci; 41 42 my $heap = Heap::Fibonacci->new; 43 my $elem; 44 45 foreach $i ( 'aa'..'bz' ) { 46 $elem = StrElem( $i ); 47 $heap->add( $elem ); 48 } 49 50 while( defined( $elem = $heap->extract_top ) ) { 51 print "Smallest is ", $elem->val, "\n"; 52 } 53 54=head1 DESCRIPTION 55 56Heap::Elem::Str is used to wrap string values into an element 57that can be managed on a heap. The top of the heap will have 58the smallest element still remaining. (See L<Heap::Elem::StrRev> 59if you want the heap to always return the largest element.) 60 61The details of the Elem interface are described in L<Heap::Elem>. 62 63The details of using a Heap interface are described in L<Heap>. 64 65=head1 AUTHOR 66 67John Macdonald, john@perlwolf.com 68 69=head1 COPYRIGHT 70 71Copyright 1998-2007, O'Reilly & Associates. 72 73This code is distributed under the same copyright terms as perl itself. 74 75=head1 SEE ALSO 76 77Heap(3), Heap::Elem(3), Heap::Elem::StrRev(3). 78 79=cut 80