daggy

Crates.iodaggy
lib.rsdaggy
version0.9.0
created_at2015-10-08 16:29:50.956292+00
updated_at2025-04-17 23:12:56.936653+00
descriptionA directed acyclic graph data structure library. It is Implemented on top of petgraph's Graph data structure and attempts to follow similar conventions where suitable.
homepagehttps://github.com/mitchmindtree/daggy
repositoryhttps://github.com/mitchmindtree/daggy.git
max_upload_size
id3175
size140,080
Azriel Hoh (azriel91)

documentation

README

daggy Actions Status Crates.io Crates.io docs.rs

A directed acyclic graph data structure for Rust.

It is implemented on top of petgraph's Graph data structure and attempts to follow similar conventions where suitable.

Usage

Use daggy in your project by adding it to your Cargo.toml dependencies:

[dependencies]
daggy = "0.9.0"

# Enables the `StableDag` type.
daggy = { version = "0.9.0", features = ["stable_dag"] }

# Allows the `Dag` to be serialized and deserialized.
daggy = { version = "0.9.0", features = ["serde-1"] }

Examples

Please see the tests directory for some basic usage examples.

Transitive reduction:

use daggy::Dag;

let mut dag = Dag::<&str, &str>::new();

// Reduce edges:
//
// ```text
// # Before:          | # After:
//                    |
// a -> b ----.       | a -> b ----.
//  |         |       |  |         |
//  |-> c ----|----.  |  '-> c     |
//  |    \    |    |  |       \    |
//  |     \   v    |  |        \   v
//  |------>> d    |  |         '> d
//  |          \   v  |             \
//  '----------->> e  |              '> e
// ```

let a = dag.add_node("a");

let (_, b) = dag.add_child(a, "a->b", "b");
let (_, c) = dag.add_child(a, "a->c", "c");
let (_, d) = dag.add_child(a, "a->d", "d");
let (_, e) = dag.add_child(a, "a->e", "e");

dag.add_edge(b, d, "b->d").unwrap();

dag.add_edge(c, d, "c->d").unwrap();
dag.add_edge(c, e, "c->e").unwrap();

dag.add_edge(d, e, "d->e").unwrap();

assert_eq!(dag.edge_count(), 8);

dag.transitive_reduce(vec![a]);

let mut edges = dag.graph().edge_weights().copied().collect::<Vec<_>>();
edges.sort();
assert_eq!(dag.edge_count(), 5);
assert_eq!(&edges, &["a->b", "a->c", "b->d", "c->d", "d->e"]);

License

Dual-licensed to be compatible with the petgraph and Rust projects.

Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.

Commit count: 0

cargo fmt