Crates.io | xdag |
lib.rs | xdag |
version | 0.1.4 |
source | src |
created_at | 2022-09-01 09:22:08.375644 |
updated_at | 2022-09-15 09:00:43.885145 |
description | A simple Rust DAG(Directed Acyclic Graph) lib |
homepage | |
repository | https://github.com/xstater/xdag/ |
max_upload_size | |
id | 656554 |
size | 29,448 |
A simple DAG (Directed Acyclic Graph) library
This lib just provides a data-structure to store DAG with checking. It doesn't contain any algorithm about DAG.
XDAG stores DAG by HashMap. it CANNOT ensure the order of children and edges
// 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))
}