graph

Generated by tinox doc

tinox.core.graph, bundled with the compiler and also available as a standalone tinox-central package.

Shortest path

import tinox.core.graph
class Main
{
    fnc main() -> Int32
    {
        const 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)
        const visitor: fnc(String) -> Nothing = id => {
            println("visiting " + id)
        }
        Graph::bfs(g, "a", visitor)
        const dist: Float64 = Graph::dijkstra(g, "a", "c")
        println("shortest distance: " + dist.toString())
        return 0
    }
}

class Graph<V>

Fields

nodesMap<String, V>
edgesMap<String, List<GraphEdge>>

Methods

fn new() → Graph<V>
fn addNode(graph: Graph<V>, id: String, value: V) → Nothing
fn addEdge(graph: Graph<V>, from: String, to: String, weight: Float64) → Nothing
fn neighbors(graph: Graph<V>, id: String) → List<GraphEdge>
fn bfs(graph: Graph<V>, start: String, visitor: fnc(String) -> Nothing) → Nothing
fn dfs(graph: Graph<V>, start: String, visitor: fnc(String) -> Nothing) → Nothing
fn dfsHelper(graph: Graph<V>, current: String, visited: Map<String, Bool>, visitor: fnc(String) -> Nothing) → Nothing
fn dijkstra(graph: Graph<V>, start: String, end: String) → Float64

class GraphEdge

Fields

toString
weightFloat64