Files
rose-ash/lib/ocaml
giles bcaa41d1ae
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
ocaml: phase 5.1 union_find.ml baseline (10 nodes, 6 unions, 4 components)
Disjoint-set union with path compression:

  let make_uf n = Array.init n (fun i -> i)
  let rec find p x =
    if p.(x) = x then x
    else begin let r = find p p.(x) in p.(x) <- r; r end
  let union p x y =
    let rx = find p x in let ry = find p y in
    if rx <> ry then p.(rx) <- ry

After unioning (0,1), (2,3), (4,5), (6,7), (0,2), (4,6):
  {0,1,2,3} {4,5,6,7} {8} {9}  --> 4 components.

Tests Array.init with closure, recursive find, in-place .(i)<-r.

139 baseline programs total.
2026-05-10 03:59:56 +00:00
..