package A2B::PartialPath; use strict; use vars qw(@ISA); use Heap::Elem; @ISA = qw(Heap::Elem); sub new { my ($package, $from) = @_; return bless { path => A2B::Path->new, nodes => {$from => 1}, node => $from, heap_data => undef, }, $package; } sub goodness { my $self = shift; return $self->{path}->goodness; } sub node { my $self = shift; return $self->{node}; } sub contains_node { my $self = shift; my $node = shift; return $self->{nodes}{$node}; } sub path { my $self = shift; return $self->{path}; } sub new_step { my ($self, $step) = @_; my $step_to = $step->to; return bless { path => $self->{path}->new_step($step), nodes => {%{$self->{nodes}}, $step_to => 1}, node => $step_to, }, ref $self; } # comparitor for the priority queue - we want HIGH goodness values to be # returned first sub cmp { my ($a, $b) = @_; return $b->{path}->goodness <=> $a->{path}->goodness; } # get or set value slot sub val { if (@_ > 1) { die "can't set value"; } return $_[0]->{path}->goodness; } # get or set heap slot sub heap { @_ > 1 ? ($_[0]{heap_data} = $_[1]) : $_[0]{heap_data}; } 1