XDag

A simple DAG (Directed Acyclic Graph) library

Note

This lib just provides a data-structure to store DAG with checking. It doesn't contain any algorithm about DAG.

Details

XDAG stores DAG by BTreeMap. Because it can ensure the order of edges and nodes.

Docs

docs.rs

Examples

```Rust // Create a new DAG let mut dag = Dag::new(); // insert 3 nodes with data '()' dag.insertnode(2, ()); dag.insertnode(4, ()); dag.insertnode(3, ()); // insert 2 edges with data '()' dag.insertedge(2, 3, ()).unwrap(); dag.insert_edge(2, 4, ()).unwrap(); // Get all roots and leaves in DAG let roots = dag.roots().map(|(id, _)| id).collect::>(); let leaves = dag.leaves().map(|(id, _)| id).collect::>();

assert_eq!(&roots, &[2]); for id in [3, 4].iter() { assert!(leaves.contains(id)) } ```