Pure MoonBit generic graph data structures and algorithms
| Area | APIs | Complexity / constraints |
|---|---|---|
| Shortest paths | dijkstra, shortest_path, a_star, bellman_ford | O((V + E) log V) for heap-based non-negative paths; O(VE) for Bellman-Ford |
| All pairs | floyd_warshall | O(V^3) |
| Connectivity | weakly_connected_components, is_weakly_connected, transitive_closure, Tarjan SCC | O(V + E) per traversal; closure uses one BFS per source |
| Scheduling | topological_sort, topological_layers, dag_longest_paths | O(V + E) |
| Undirected analysis | kruskal_mst, prim_mst, articulation_points, bridges, greedy_coloring | O(E log E) for MST; low-link analysis is O(V + E) |
| Network algorithms | max_flow, maximum_bipartite_matching, directed Eulerian trails, min_cut | Edmonds-Karp O(VE^2); capacities are non-negative integers |
| Network analysis | PageRank, triangle count, local clustering, k-core, centrality, reciprocity, diameter | Iterative ranking plus traversal-based metrics |
| Routing and sampling | routing tables, widest paths, multi-source BFS, k-hop neighborhoods, deterministic random walks | O(V + E) for routing tables; walks are bounded |
| Visualization | to_dot, edge_list, weighted_edge_list | O(V + E) plus output size |
moon add wedarp/moongraphimport {
"wedarp/moongraph/src" @moongraph,
}
fn main {
let graph : @moongraph.Graph[String, Int] =
@moongraph.Graph::new(directed=true)
let source = graph.add_node("source")
let sink = graph.add_node("sink")
let _ = graph.add_edge(source, sink, 7)
println("\{graph.node_count()}")
}moon run cmd/demo --target wasm-gcmoon run cmd/demo --target nativemoon version --all
moon update
moon fmt
git restore -- cmd/demo/moon.pkg cmd/benchmark/moon.pkg
git diff -- '*.mbt' '*.mbti'
git diff --exit-code
moon check --target all --deny-warn
moon build --target all --deny-warn
moon test --target all --deny-warn
moon run cmd/benchmark --target wasm-gc
moon infomoon check --target wasm-gc --deny-warn
moon build --target wasm-gc --deny-warn
moon test --target wasm-gc --deny-warn
moon run cmd/demo --target wasm-gcmoon run cmd/benchmark --target wasm-gc| Workload | Input | Expected measurements |
|---|---|---|
| Zachary Karate Club | 34 nodes, 78 undirected edges | 45 triangles, 1 component, diameter 5, average distance 2.408199 |
| Compiler pipeline | 12 tasks with dependency edges | makespan 45, critical-path length 11 |
| Sparse network | 500 nodes, 600 directed edges | 500 reachable from node 0, diameter 84, distance from 0 to 499 is 67 |
Pure MoonBit generic graph data structures and algorithms