Hand-rolled union-find (DSU)
manual parent-pointer path compression: use std.dsu
domain V = 0..4
var par: [V]V = [V] v => v
fn find(v: V) -> V:
var x = v
while par[x] != x:
par[x] = par[par[x]]
x = par[x]
x
print(find(V(0)))domain V = 0..4
var d = Dsu<V>.new()
print(d.find(V(0)))Why
Hand-rolling union-find path compression (while par[x] != x: par[x] = par[par[x]] or recursive par[x] = find(par[x])) duplicates domain-safe, path-halving Dsu, DsuOf, ParityDsu, and PotentialDsu in std.dsu.
The practice it serves
A hand-written pattern the language or the standard library already says in one step. Family: S.dsu.
Not flagged
A near miss: close to the pattern, but not it.
domain V = 0..4
let par: [V]V = [V] v => v
print(par[V(0)])Turn it off
For one block, wrap it in with lint(hand_rolled_dsu: allow):. For a project, add hand_rolled_dsu = "allow" under [lints] in cp.toml.
Generated from spec/lints/hand_rolled_dsu, the same record the linter is built from.