mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #1336 from rinconjc/1321
Fix #1321 tsort handle self-loops
This commit is contained in:
commit
dbc9527b00
2 changed files with 8 additions and 1 deletions
2
src/tsort/tsort.rs
Normal file → Executable file
2
src/tsort/tsort.rs
Normal file → Executable file
|
@ -149,7 +149,7 @@ impl Graph {
|
||||||
self.init_node(from);
|
self.init_node(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.has_edge(from, to) {
|
if from != to && !self.has_edge(from, to) {
|
||||||
self.in_edges.get_mut(to).unwrap().insert(from.clone());
|
self.in_edges.get_mut(to).unwrap().insert(from.clone());
|
||||||
self.out_edges.get_mut(from).unwrap().push(to.clone());
|
self.out_edges.get_mut(from).unwrap().push(to.clone());
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,3 +8,10 @@ fn test_sort_call_graph() {
|
||||||
.run()
|
.run()
|
||||||
.stdout_is_fixture("call_graph.expected");
|
.stdout_is_fixture("call_graph.expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_sort_self_loop() {
|
||||||
|
new_ucmd!()
|
||||||
|
.pipe_in("first first\nfirst second second second")
|
||||||
|
.succeeds().stdout_only("first\nsecond\n");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue