6 releases (3 stable)
1.0.2 | Apr 16, 2021 |
---|---|
1.0.1 | Apr 7, 2021 |
0.1.2 | Apr 4, 2021 |
184 downloads per month
Used in 3 crates
(2 directly)
8KB
147 lines
szyk-rs
Generic topsort for Rust
Example
use szyk::Node;
use szyk;
let result = szyk::sort(
&[
Node::new("wooden pickaxe", vec!["planks", "sticks"], "Pickaxe"),
Node::new("planks", vec!["wood"], "Planks"),
Node::new("sticks", vec!["planks"], "Sticks"),
Node::new("wood", vec![], "Wood"),
],
"wooden pickaxe",
);
assert_eq!(result, Ok(vec!["Wood", "Planks", "Sticks", "Pickaxe"]));
lib.rs
:
Generic topological sort algorithm (depth-first)
Examples
use szyk::Node;
use szyk;
let result = szyk::sort(
&[
Node::new("wooden pickaxe", vec!["planks", "sticks"], "Pickaxe"),
Node::new("planks", vec!["wood"], "Planks"),
Node::new("sticks", vec!["planks"], "Sticks"),
Node::new("wood", vec![], "Wood"),
],
"wooden pickaxe",
);
assert_eq!(result, Ok(vec!["Wood", "Planks", "Sticks", "Pickaxe"]));