Skip to content

Commit

Permalink
tsort: allow independent nodes (#761)
Browse files Browse the repository at this point in the history
* When a node refers to itself in a pair it means the node exists but does not depend on anything
* Previously, this input would result in a "cycle" error
* In test file, allow node 'd' to be added to npred-hash with a predecessor count of zero, so it can appear in list-list
* The inner "foreach" loop does not execute for node 'd' because it has no dependency; it has no need for an entry in succ-hash

%perl cat in.tsort2
a b
b
  c
d d
%perl tsort.old in.tsort2
a
b
c
tsort.old: cycle detected
%perl tsort in.tsort2
a
b
c
d
%perl cat in.tsort3
a a
%perl tsort in.tsort3
a
  • Loading branch information
mknos authored Oct 16, 2024
1 parent 863b0c2 commit 11555c6
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions bin/tsort
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ while (@input) {
next if defined $pairs{$l}{$r};
$pairs{$l}{$r}++;
$npred{$l} += 0;
next if $l eq $r;
++$npred{$r};
push @{$succ{$l}}, $r;
}
Expand Down

0 comments on commit 11555c6

Please sign in to comment.