Expand description
§Graaf
Functions and types for working with graphs
§Examples
use {
graaf::{
algo::bfs::single_pair_shortest_path,
op::{
AddEdge,
Indegree,
},
},
std::collections::HashSet,
};
let mut graph: [HashSet<usize>; 4] = [
HashSet::new(),
HashSet::new(),
HashSet::new(),
HashSet::new(),
];
// ╭───╮ ╭───╮
// │ 0 │ → │ 1 │
// ╰───╯ ╰───╯
// ↑ ↓
// ╭───╮ ╭───╮
// │ 3 │ │ 2 │
// ╰───╯ ╰───╯
graph.add_edge(3, 0);
graph.add_edge(0, 1);
graph.add_edge(1, 2);
assert_eq!(graph.indegree(0), 1);
assert_eq!(graph.indegree(1), 1);
assert_eq!(graph.indegree(2), 1);
assert_eq!(graph.indegree(3), 0);
let path = single_pair_shortest_path(&graph, 3, 2);
assert_eq!(path, Some(vec![3, 0, 1, 2]));
Modules§
- Graph algorithms
- Graph generators
- Operations on graphs
- Cross-module properties and strategies.
- Custom graph representations