From 63f7f895888b0bde7c60f1d5cd18399acec161f2 Mon Sep 17 00:00:00 2001 From: doy Date: Sun, 14 Dec 2008 17:07:51 -0500 Subject: factor out neighbor calculation into a method --- lib/Graph/Implicit.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Graph/Implicit.pm b/lib/Graph/Implicit.pm index 26f4f5c..828c67f 100644 --- a/lib/Graph/Implicit.pm +++ b/lib/Graph/Implicit.pm @@ -28,6 +28,9 @@ sub edges { } sub neighbors { + my $self = shift; + my ($from) = @_; + return $self->($from); } # traversal @@ -73,7 +76,7 @@ sub dijkstra { ($max_vert, $max_score) = ($vertex, $score) if ($score > $max_score); } - $neighbors{$vertex} = [$self->($vertex)] + $neighbors{$vertex} = [$self->neighbors($vertex)] unless exists $neighbors{$vertex}; for my $neighbor (@{ $neighbors{$vertex} }) { my ($vert_n, $weight_n) = @{ $neighbor }; -- cgit v1.2.3-54-g00ecf