Data and Math

vgraph

Graph algorithms over weighted adjacency lists kept in a plain map.

Released v1.0.0 · 2026-09-28
Import
use "stdlib/graph.ven"

Traversal, shortest paths, in degrees and topological order.

vgraph.ven
g = graph_new()
graph_add_edge(g, "a", "b", 1, no)
graph_add_edge(g, "b", "c", 2, no)
graph_add_edge(g, "a", "c", 5, no)
print shortest_path(g, "a", "c")
Reference (14 functions)

API reference

graph_new()

Builds a new, empty graph.

graph_new()

graph_add_node(g, node)

Registers node in g with an empty neighbor list, if it isn't already present.

g = graph_new()
graph_add_node(g, "a")

graph_add_edge(g, from_node, to_node, weight, directed)

Adds a weighted edge from from_node to to_node in g, auto-registering both endpoints.

g = graph_new()
graph_add_edge(g, "a", "b", 1, no)

graph_neighbors(g, node)

Gives back the List of (neighbor, weight) Tuples reachable directly from node in g.

g = graph_new()
graph_add_edge(g, "a", "b", 1, no)
graph_neighbors(g, "a")

bfs_order(g, start)

g = graph_new()
graph_add_edge(g, "a", "b", 1, no)
bfs_order(g, "a")

dfs_order(g, start)

g = graph_new()
graph_add_edge(g, "a", "b", 1, no)
dfs_order(g, "a")

shortest_path(g, start, end)

Gives back the lowest-weight path from start to end in g, as a List of nodes.

g = graph_new()
graph_add_edge(g, "a", "b", 1, no)
graph_add_edge(g, "b", "c", 2, no)
graph_add_edge(g, "a", "c", 5, no)
shortest_path(g, "a", "c")

graph_in_degrees(g)

g = graph_new()
graph_add_edge(g, "a", "b", 1, yes)
graph_add_edge(g, "b", "c", 1, yes)
graph_in_degrees(g)

graph_kahn_order(g)

Runs Kahn's algorithm on g, giving back a full or partial topological order.

g = graph_new()
graph_add_edge(g, "a", "b", 1, yes)
graph_add_edge(g, "b", "c", 1, yes)
graph_kahn_order(g)

has_cycle(g)

Tests whether g contains a cycle, treating every edge as directed.

g = graph_new()
graph_add_edge(g, "a", "b", 1, yes)
graph_add_edge(g, "b", "a", 1, yes)
has_cycle(g)

topological_order(g)

Gives back a valid topological order of g, raising if g has a cycle.

g = graph_new()
graph_add_edge(g, "a", "b", 1, yes)
graph_add_edge(g, "b", "c", 1, yes)
topological_order(g)

graph_undirected_adjacency(g)

g = graph_new()
graph_add_edge(g, "a", "b", 1, yes)
graph_undirected_adjacency(g)

connected_components(g)

Gives back the weakly connected components of g, as a List of Lists of nodes.

g = graph_new()
graph_add_edge(g, "a", "b", 1, no)
graph_add_edge(g, "b", "c", 2, no)
connected_components(g)

minimum_spanning_tree(g)

Builds a minimum spanning tree of g using Prim's algorithm.

g = graph_new()
graph_add_edge(g, "a", "b", 4, no)
graph_add_edge(g, "b", "c", 2, no)
graph_add_edge(g, "a", "c", 5, no)
minimum_spanning_tree(g)

Get notified when vgraph changes

Get notified about

New versions and security advisories.

New and updated packages, once a day.

News on the math model built in Venutian.