Documentation

CslibFrontier.Foundations.Data.Array.CommonPrefix

Extending a common prefix of two array suffixes #

Kasai's LCP array construction and the Z-algorithm both resume comparisons after a prefix whose length is already known. Array.extendLcp compares the remaining entries in place. Array.extendLcp_eq_add_lcpLen specifies how much it adds, and Array.extendLcp_eq_lcpLen recovers the full length when the skipped prefix is known to agree.

@[irreducible]
def Array.extendLcp {α : Type u_1} [DecidableEq α] (w : Array α) (i j h : ℕ) :

Starting with length h, compare entries at i + h and j + h and advance while they agree. The first h entries of the two suffixes are skipped.

theorem Array.extendLcp_eq_add_lcpLen {α : Type u_1} [DecidableEq α] (w : Array α) (i j h : ℕ) :
w.extendLcp i j h = h + (List.drop (i + h) w.toList).lcpLen (List.drop (j + h) w.toList)

The returned length is the starting length plus the common prefix of the unexamined suffixes.

theorem Array.extendLcp_eq_lcpLen {α : Type u_1} [DecidableEq α] (w : Array α) (i j h : ℕ) (hh : h ≤ (List.drop i w.toList).lcpLen (List.drop j w.toList)) :

Given a known common prefix of length h, resuming the scan returns the full common-prefix length of the suffixes at i and j.