Ade-topological-sort
ade-topological-sort provides a topological sorting algorithm for directed graphs. It can handle graphs with cycles (by returning an error) and allows for custom sorting of nodes based on provided keys.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage Example
The topological_sort function can sort the nodes of a directed graph such that for every directed edge from node u to node v, u comes before v in the ordering. It also supports sorting based on a custom key function, allowing for deterministic output when multiple valid topological sorts exist.
This example demonstrates sorting a graph where nodes are ordered by their keys in descending order.
use topological_sort;
use build_graph;
use GraphViewTrait;
use Node;
Documentation
The complete documentation is available on docs.rs.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Benchmark
# Run topological_sort_bench benchmark
cargo bench --bench topological_sort_bench
# Save baseline
cargo bench --bench topological_sort_bench -- --save-baseline before_optimization
# Compare with baseline
cargo bench --bench topological_sort_bench -- --baseline before_optimization