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