xdag 0.1.4

A simple Rust DAG(Directed Acyclic Graph) lib
Documentation
  • Coverage
  • 93.94%
    31 out of 33 items documented0 out of 23 items with examples
  • Size
  • Source code size: 29.11 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 6.98 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • xstater/xdag
    0 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • xstater

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 HashMap. it CANNOT ensure the order of children and edges

Docs

docs.rs

Examples

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

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