Crate graphsearch [] [src]

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 Nodes

Node

A node in the graph, made up a any content type T and a Vec of vertices

Vertex

A vertex between two Nodes with an associated i32 cost and a target node. Vertex derives Copy, Debug, Eq and PartialEq and implements Ord and PartialOrd as we use it ordered compound types.