Expand description
A graph representation and search library
§Example
use graphsearch::{Graph, Node, Vertex};
let rawgraph = vec![Node{content: "Helsinki",
adjacent: vec![Vertex{cost: 20, node: 1},
Vertex{cost: 50, node: 2}]},
Node{content: "Turku",
adjacent: vec![Vertex{cost: 30, node: 2}]},
Node{content: "Tampere",
adjacent: Vec::new()}];
let g = Graph::new(rawgraph);
let start = 0;
let target = "Tampere";
let res = g.search(start, target); // uses dijkstras algorithm
match res {
None => {
println!("Search returned None");
}
Some(result) => {
println!("Search returned a path: {:?}", result);
println!("The returned path cost: {}", g.cost_of_path(&result));
}
}
Structs§
- Graph
- A graph, represeted by as a weighted
Adjacency list of
Node
s - Node
- A node in the graph, made up a any content type
T
and aVec
of vertices - Vertex
- A vertex between two
Node
s with an associatedi32
cost and a target node.Vertex
derivesCopy
,Debug
,Eq
andPartialEq
and implementsOrd
andPartialOrd
as we use it ordered compound types.