Graphlib is a simple and powerful rust library for the graph data-structure.
This library attempts to provide a generic api for building, mutating and iterating over graphs that is similar to that of other data-structures in rust i.e. Vec
, HashMap
, VecDeque
, etc.
use graphlib::Graph;
let mut graph: Graph<usize> = Graph::new();
let id1 = graph.add_vertex(1);
let id2 = graph.add_vertex(2);
graph.add_edge(&id1, &id2);
assert_eq!(*graph.fetch(&id1).unwrap(), 1);
assert_eq!(*graph.fetch(&id2).unwrap(), 2);
assert_eq!(graph.vertex_count(), 2);
assert_eq!(graph.edge_count(), 1);
graph.remove(&id1);
assert_eq!(graph.vertex_count(), 1);
assert_eq!(graph.edge_count(), 0);