Full documentation available here
Choosed adjacency matrix implementation.
Create empty graph with u32
node and String
edge weight:
let mut g = MatrixGraph::<u32, String>::default()
Or create from IntoIterator
:
let edges = [
(1, 2, 3),
(3, 4, 7),
(1, 3, 4),
];
let g = MatrxiGraph::<u32, u32>::from_edges(edges.into_iter());
Adding nodes and edges:
let mut g = MatrixGraph::<u32, String>::default()
let first = g.add_node(34);
let second = g.add_node(52);
g.add_edge(first, second, "First");
g.add_edge(second, first, "Second");
Removing nodes and edges:
g.remove_node(2);
g.remove_edge(0, 1);
Iterating over breadth first traverse of graph:
let start_node_idx = 0;
for entry in g.bfs_iter(start_node_idx) {
println!("Node: {}, edges: {:?}", entry.node, entry.edges);
}
Deserialize from Trivial Graph Format:
let tgf = load_tgf_as_str();
let g = serialization::de_tgf::<u32, String>(tgf).expect("Something bad");