Subject: | UnionFind: Repeated adds clobbers graph component information |
If a vertex which was already in the graph is added again, the
information about what graph component it was in is lost. Here is an
example:
$graph = Graph::UnionFind->new;
$graph->add('a');
$graph->union('a','b');
$graph->add('a'); # 'a' is no longer related to 'b'
I have attached a patch which resolves this issue.
Keep up the good work,
Antonio
Subject: | fix-repeated-add.diff |
--- UnionFind.pm.orig 2008-10-03 20:32:10.000000000 +0200
+++ UnionFind.pm 2008-10-03 20:32:40.000000000 +0200
@@ -12,7 +12,7 @@
sub add {
my ($self, $elem) = @_;
- $self->{ $elem } = [ $elem, 0 ];
+ $self->{ $elem } = [ $elem, 0 ] unless defined($self->{$elem});
}
sub has {