graph
Generated by tinox doc
A generic directed graph (Graph<V>) with weighted edges: add nodes/edges, breadth-first and depth-first traversal with a visitor callback, and Dijkstra shortest-path between two nodes.
Shortest path
import tinox.core.graph;
class Main
{
fnc main() -> Int32
{
let g: Graph<String> = Graph::new();
Graph::addNode(g, "a", "Start");
Graph::addNode(g, "b", "Middle");
Graph::addNode(g, "c", "End");
Graph::addEdge(g, "a", "b", 1.0);
Graph::addEdge(g, "b", "c", 2.0);
Graph::addEdge(g, "a", "c", 5.0);
let visitor: fnc(String) -> Nothing = id => {
println("visiting " + id);
};
Graph::bfs(g, "a", visitor);
let dist: Float64 = Graph::dijkstra(g, "a", "c");
println("shortest distance: " + dist.toString());
return 0;
}
}
class GraphEdge
Fields
to | String | |
weight | Float64 |