A comprehensive graph algorithm library for MoonBit, providing graph data structures
and 17+ classic graph algorithms. Pure MoonBit — no FFI dependencies.
Installation
Add to your moon.mod:
dependencies {
"xiaohedehub/opentg": "0.1.0"
}
Or via CLI:
moon add xiaohedehub/opentg
Quick Start
let g = @graph.Graph::new()
// Add nodes
let a = g.add_node("Alice")
let b = g.add_node("Bob")
let c = g.add_node("Carol")
// Add edges
g.add_edge(a, b, 1)
g.add_edge(b, c, 2)
g.add_edge(a, c, 4)
// BFS traversal
let bfs_order = @traversal.bfs(g, a)
// => [a, b, c]
// Shortest path (Dijkstra)
let dists = @path.dijkstra(g, a, edge_cost=fn(_, e) {
g.edge_weight(e).unwrap()
})
// dists[a] = 0, dists[b] = 1, dists[c] = 3
// Check for cycles
assert_eq!(@properties.is_cyclic_directed(g), false)
Package Structure
Package
Description
graph
Core graph data structures: Graph[N, E], NodeIndex, EdgeIndex
moonbit-graph
A comprehensive graph algorithm library for MoonBit, providing graph data structures and 17+ classic graph algorithms. Pure MoonBit — no FFI dependencies.
Installation
Add to your
moon.mod:Or via CLI:
Quick Start
Package Structure
graphGraph[N, E],NodeIndex,EdgeIndexerrorsCycle,NegativeCycletraversalpathmstconnectivityflowpropertiesgeneratorsbenchAlgorithms
Traversal
@traversal.bfs(g, start)@traversal.dfs(g, start)@traversal.toposort(g)Shortest Path
@path.dijkstra(g, source, edge_cost)@path.astar(g, start, is_goal, edge_cost, heuristic)@path.bellman_ford(g, source, edge_cost)@path.floyd_warshall(g, edge_cost)Minimum Spanning Tree
@mst.mst_kruskal(g, edge_weight)@mst.mst_prim(g, root, edge_weight)Connectivity
@connectivity.tarjan_scc(g)@connectivity.kosaraju_scc(g)@connectivity.connected_components(g)@connectivity.bridges(g)@connectivity.articulation_points(g)Maximum Flow
@flow.edmonds_karp(g, s, t, capacity)@flow.dinic(g, s, t, capacity)Properties
@properties.is_cyclic_directed(g)@properties.is_cyclic_undirected(g)@properties.is_bipartite(g)@properties.has_path(g, from, to)Graph Operations
Key Design Decisions
NodeIndexandEdgeIndexare distinct structs — no accidental swapsContributing
This project is an entry in the 2026 CCF Open Source Innovation Competition (MoonBit track). Contributions and feedback are welcome!
License
Apache License 2.0 — see LICENSE