home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / HeapElem.pm < prev    next >
Encoding:
Perl POD Document  |  1999-08-18  |  1.4 KB  |  85 lines

  1. package Graph::HeapElem;
  2.  
  3. use strict;
  4. use vars qw($VERSION @ISA);
  5. use Heap::Elem;
  6.  
  7. require Exporter;
  8.  
  9. @ISA = qw(Exporter Heap::Elem);
  10.  
  11. $VERSION = 0.01;
  12.  
  13. =head1 NAME
  14.  
  15. Graph::HeapElem - internal use only
  16.  
  17. =head1 SYNOPSIS
  18.  
  19. =head1 DESCRIPTION
  20.  
  21. B<INTERNAL USE ONLY> for the Graph module
  22.  
  23. =head1 COPYRIGHT
  24.  
  25. Copyright 1999, O'Reilly & Associates.
  26.  
  27. This code is distributed under the same copyright terms as Perl itself.
  28.  
  29. =cut
  30.  
  31. # Preloaded methods go here.
  32.  
  33. sub new {
  34.     my $class = shift;
  35.     $class = ref($class) || $class;
  36.  
  37.     # two slot array, 0 for the vertex, 1 for use by Heap
  38.     my $self = [ [ @_ ], undef ];
  39.  
  40.     return bless $self, $class;
  41. }
  42.  
  43. # get or set vertex slot
  44. sub vertex {
  45.     my $self = shift;
  46.     @_ ? ($self->[0]->[0] = shift) : $self->[0]->[0];
  47. }
  48.  
  49. # get or set weight slot
  50. sub weight {
  51.     my $self = shift;
  52.     @_ ?
  53.       ($self->[0]->[1]->{ $self->vertex } = shift) :
  54.        $self->[0]->[1]->{ $self->vertex };
  55. }
  56.  
  57. # get or set parent slot
  58. sub parent {
  59.     my $self = shift;
  60.     @_ ?
  61.       ($self->[0]->[2]->{ $self->vertex } = shift) :
  62.        $self->[0]->[2]->{ $self->vertex };
  63. }
  64.  
  65. # get or set heap slot
  66. sub heap {
  67.     my $self = shift;
  68.     @_ ? ($self->[1] = shift) : $self->[1];
  69. }
  70.  
  71. # compare two vertices
  72. sub cmp {
  73.     my ($u, $v) = @_;
  74.  
  75.     my ($uw, $vw) = ( $u->weight, $v->weight );
  76.  
  77.     if ( defined $uw ) {
  78.         return defined $vw ? $uw <=> $vw : -1;
  79.     } else {
  80.         return defined $vw ? 1 : 0;
  81.     }
  82. }
  83.  
  84. 1;
  85.