Gamma

A graph library for Rust.

gamma provides primitives and traversals for working with graphs.

Usage

Add this to your Cargo.toml:

toml [dependencies] gamma = "0.1"

Examples

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::>(), vec![ &0, &1, &2 ]); asserteq!(graph.hasnode(&0), true); asserteq!(graph.neighbors(&1).unwrap().collect::>(), vec![ &0, &2 ]); asserteq!(graph.degree(&1).unwrap(), 2); asserteq!(graph.edges().collect::>(), vec![ (&0, &1), (&1, &2) ]); asserteq!(graph.hasedge(&0, &1).unwrap(), true); asserteq!(graph.hasedge(&1, &0).unwrap(), true); asserteq!(graph.hasedge(&0, &2).unwrap(), false); } ```

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::>(), vec![ (&0, &1, false), (&1, &2, false), (&2, &0, true) ]); } ```

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::>(), vec![ (&0, &1, false), (&0, &2, false), (&1, &2, true) ]); } ```

Versions

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.

License

gamma is distributed under the terms of the MIT License. See LICENSE-MIT and COPYRIGHT for details.