A graph library for Rust.
gamma provides primitives and traversals for working with graphs.
Add this to your Cargo.toml
:
toml
[dependencies]
gamma = "0.1"
HashGraph
is the reference Graph
implementation.
```rust use gamma::graph::Graph; use gamma::graph::HashGraph;
fn main() { let mut graph = HashGraph::build(vec![ 0, 1, 2 ], vec![ (&0, &1, "a"), (&1, &2, "b") ] ).unwrap();
asserteq!(graph.isempty(), false);
asserteq!(graph.order(), 3);
asserteq!(graph.size(), 2);
asserteq!(graph.nodes().collect::
Depth-first traversal is implemented as an Iterator
.
```rust use gamma::graph::Graph; use gamma::graph::HashGraph; use gamma::traversal::depth_first;
fn main() { let graph = HashGraph::build(vec![ 0, 1, 2 ], vec![ (&0, &1, ()), (&1, &2, ()), (&2, &0, ()), ]).unwrap(); let traversal = depth_first(&graph, &0).unwrap();
assert_eq!(traversal.collect::
Breadth-first traversal is also implemented as an Iterator
.
```rust use gamma::graph::Graph; use gamma::graph::HashGraph; use gamma::traversal::breadth_first;
fn main() { let graph = HashGraph::build(vec![ 0, 1, 2 ], vec![ (&0, &1, ()), (&1, &2, ()), (&2, &0, ()), ]).unwrap(); let traversal = breadth_first(&graph, &0).unwrap();
assert_eq!(traversal.collect::
Gamma is not yet stable, but care is taken to limit breaking changes and warn with deprecation whenever possible. Patch version never introduce breaking changes.
gamma is distributed under the terms of the MIT License. See LICENSE-MIT and COPYRIGHT for details.