Skip to content

Commit 1aaf383

Browse files
committed
fix:Handling vertexes without edges in .index-graph().
1 parent b55eaae commit 1aaf383

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lib/Graph.rakumod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,13 +511,22 @@ class Graph
511511
%index{$vertex} = $prefix ~ $index++;
512512
}
513513

514+
my %seen;
514515
my %new-adjacency-list;
515516
for self.edges(:dataset) -> %e {
516517
%new-adjacency-list{%index{%e<from>}}{%index{%e<to>}} = %e<weight>;
517518
if !self.directed {
518519
%new-adjacency-list{%index{%e<to>}}{%index{%e<from>}} = %e<weight>;
519520
}
521+
%seen{%e<from>}++;
522+
%seen{%e<to>}++
520523
}
524+
525+
# In case there are vertices with no edges
526+
for @vs.grep({ %seen{$_}:!exists }) -> $v {
527+
%new-adjacency-list.push( %index{$v} => {} )
528+
}
529+
521530
my $vertex-coordinates = do if self.vertex-coordinates ~~ Map:D {
522531
self.vertex-coordinates.map({ %index{$_.key} => $_.value }).Hash
523532
} else { Whatever }

0 commit comments

Comments
 (0)