Skip Menu |

This queue is for tickets about the Graph CPAN distribution.

Report information
The Basics
Id: 13195
Status: resolved
Priority: 0/
Queue: Graph

People
Owner: Nobody in particular
Requestors: nospam-abuse [...] bloodgate.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.65
Fixed in: (no value)



Subject: add_vertex_get_id/add_edge_get_id() return wrong result on first call
Moin, the first time you call add_edge_get_id(), you do not get back the expected ID "0", but an array ref containing the IDs of the two nodes (aka "[0,1]"). Here is a sample script to demonstrate the problem: # cat graph.pl #!/usr/bin/perl -w use Graph; use Data::Dumper; use strict; my $graph = Graph->new (multiedged => 1); for (0..2) { print "Adding 'A' - 'B'\n"; my $id = $graph->add_edge_get_id( 'A', 'B'); print Dumper($id); my @ids = $graph->get_multiedge_ids('A','B'); print "IDs:\n", Dumper(\@ids); } # perl graph.pl Adding 'A' - 'B' $VAR1 = [ 0, 1 ]; IDs: $VAR1 = [ '0' ]; Adding 'A' - 'B' $VAR1 = 1; IDs: $VAR1 = [ '1', '0' ]; Adding 'A' - 'B' $VAR1 = 2; IDs: $VAR1 = [ '1', '0', '2' ]; I am pretty sure it has something to do with "0" being false, while "1" etc is true. Starting the IDs simple with "1" might solve that, or find out if there is somewhere along the code path a "$ID || ..." :) Some misc. things I noticed while hunting the bug: * add_vertex_get_id() has the same problem (returning 'A' on first call instead of '0') * Using "return " is a bit wastefull, I am sure you could eliminate it in a few places and thus improve performance :o) * add_edge_get_id() always checks multiedged(). This should be a per-graph flag, which can be queried fast. Maybe it even is, but traveling through the source it seems to call at least two subroutines to find this out and somewhere along the path I lost track at what it actually does to find out whether the graph is multiedged or not :) * The documentation for the multiedged methods could be a bit more verbose. For instance, it is unclear in what order get_multiedge_ids() returns the results. * Graph requires Data::Dumper. It would be better if it required it only inside _dump() so that other modules do not get Data::Dumper just by loading Graph :) Thanx for your work (sorry to cause you more :), Tels
[TELS - Fri Jun 10 15:12:33 2005]: Show quoted text
> Moin, > > the first time you call add_edge_get_id(), you do not get back the > expected ID "0", but an array ref containing the IDs of the two > nodes (aka "[0,1]"). Here is a sample script to demonstrate the > problem: > > # cat graph.pl > #!/usr/bin/perl -w > > use Graph; > use Data::Dumper; > use strict; > > my $graph = Graph->new (multiedged => 1); > > for (0..2) > { > print "Adding 'A' - 'B'\n"; > my $id = $graph->add_edge_get_id( 'A', 'B'); > > print Dumper($id); > > my @ids = $graph->get_multiedge_ids('A','B'); > print "IDs:\n", Dumper(\@ids); > } > > > # perl graph.pl > Adding 'A' - 'B' > $VAR1 = [ > 0, > 1 > ]; > IDs: > $VAR1 = [ > '0' > ]; > Adding 'A' - 'B' > $VAR1 = 1; > IDs: > $VAR1 = [ > '1', > '0' > ]; > Adding 'A' - 'B' > $VAR1 = 2; > IDs: > $VAR1 = [ > '1', > '0', > '2' > ]; > > I am pretty sure it has something to do with "0" being false, while > "1" etc is true. Starting the IDs simple with "1" might solve that, > or find out if there is somewhere along the code path a "$ID || > ..." :) > > Some misc. things I noticed while hunting the bug: > > * add_vertex_get_id() has the same problem (returning 'A' on first > call instead of '0') > * Using "return " is a bit wastefull, I am sure you could eliminate it > in a few places and thus improve performance :o) > * add_edge_get_id() always checks multiedged(). This should be a per- > graph flag, which can be queried fast. Maybe it even is, but > traveling through the source it seems to call at least two > subroutines to find this out and somewhere along the path I lost > track at what it actually does to find out whether the graph is > multiedged or not :) > * The documentation for the multiedged methods could be a bit more > verbose. For instance, it is unclear in what order > get_multiedge_ids() returns the results. > * Graph requires Data::Dumper. It would be better if it required it > only inside _dump() so that other modules do not get Data::Dumper > just by loading Graph :) > > Thanx for your work (sorry to cause you more :), > > Tels
Please retry with Graph 0.66.