diff options
author | doy <doy@tozt.net> | 2008-12-15 03:32:23 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2008-12-15 03:32:23 -0500 |
commit | b758557ca8b972ca8c559f5150bb2769219aa796 (patch) | |
tree | 77c08633acfec9e55352c74abffbd48f8a6878e7 | |
parent | bd4cb096dea79fbde13f8fa5f18cfcccb8ad1548 (diff) | |
download | graph-implicit-b758557ca8b972ca8c559f5150bb2769219aa796.tar.gz graph-implicit-b758557ca8b972ca8c559f5150bb2769219aa796.zip |
implement prim in terms of _traversal
-rw-r--r-- | lib/Graph/Implicit.pm | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Graph/Implicit.pm b/lib/Graph/Implicit.pm index 095de51..49935dd 100644 --- a/lib/Graph/Implicit.pm +++ b/lib/Graph/Implicit.pm @@ -67,8 +67,6 @@ sub is_bipartite { # traversal -# XXX: if we can generalize @bag to allow for a heap, then we can implement -# prim with this too sub _traversal { my $self = shift; my ($start, $code, $create, $notempty, $insert, $remove) = @_; @@ -117,6 +115,13 @@ sub boruvka { } sub prim { + my $self = shift; + my ($start, $code) = @_; + return $self->_traversal($start, $code, + sub { Heap::Simple->new(elements => 'Any') }, + sub { $_[0]->count }, + sub { $_[0]->key_insert($_[2], $_[1]) }, + sub { $_[0]->extract_top }); } sub kruskal { |