← All lints

hand_rolled_binary_lifting

L0519Idiomswarn

Hand-rolled binary lifting table

manual up[k][v] = up[k - 1][up[k - 1][v]] table: use std.tree

Flagged
var up = [[0, 0, 1], [0, 0, 0]]
for k in 1..2:
    for v in 0..3:
        up[k][v] = up[k - 1][up[k - 1][v]]
print(up[1][2])
Write instead
domain V = 0..3
var jt = JumpTree<V>.new()
jt.add(V(1), V(0))
jt.add(V(2), V(1))
print(jt.ancestor(V(2), 2))

Why

Hand-rolling a binary lifting ancestor table (up[k, v] = up[k - 1, up[k - 1, v]]) duplicates Rooted.lca / Rooted.ancestor and JumpTree in std.tree.

The practice it serves

A hand-written pattern the language or the standard library already says in one step. Family: S.tree.

Not flagged

A near miss: close to the pattern, but not it.

Near miss
var up = [[0, 0, 1], [0, 0, 0]]
for v in 0..3:
    up[1][v] = up[0][v] + 1
print(up[1][2])

Turn it off

For one block, wrap it in with lint(hand_rolled_binary_lifting: allow):. For a project, add hand_rolled_binary_lifting = "allow" under [lints] in cp.toml.

Generated from spec/lints/hand_rolled_binary_lifting, the same record the linter is built from.