Documentation

CslibFrontier.DataStructure.Dictionary.SuccinctWhpSwarBTreeInsert

Top-Down Split-Only SWAR B+-Tree Insertion and ValidWhpSlice Bundle #

This module completes the functional correctness and excess-key split-potential proof for descendSplitToLeaf and btreeInsert and packages the slice-level ValidWhpSlice invariant specialized to SuccinctWhp parameters.

Main definitions #

Main results #

References #

Section 1: Inductive correctness and potential bound for descendSplitToLeaf #

Lanes and child intervals after wordInsertAt #

Splitting child r of a branch inserts the promoted separator at key lane r and the new right child at value lane r + 1. The right half then sits at position r.succ and the old child k (the left half when k = r) at position r.succ.succAbove k.

Section 2: Full btreeInsert specification and ValidSlice invariant #

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.btreeInsert_subtree_spec {fpBits W_val tMin : ℕ} {sl : BTreeSlice} {mapFn : ℕ → Option ℕ} {T : BTreeTree} {q val : ℕ} (ht3 : 3 ≤ tMin) (hcap : 2 * tMin < 2 ^ (fpBits + 2)) (halloc_pos : 1 ≤ sl.alloc) (halloc_val : sl.alloc + hMaxBTree + 2 < 2 ^ W_val) (hroot : T.rootIdx = sl.root) (hv : ValidSubtree true fpBits W_val tMin sl.alloc sl.nodes 0 (2 ^ fpBits - 1) mapFn T) (hht_lt : T.height < hMaxBTree) (hq : q < 2 ^ fpBits) (hval : val < 2 ^ W_val) :
have sl' := btreeInsert fpBits W_val tMin sl q val; 1 ≤ sl'.alloc ∧ sl'.alloc ≤ sl.alloc + hMaxBTree + 2 ∧ ∃ (T' : BTreeTree), T'.rootIdx = sl'.root ∧ T'.height ≤ T.height + 1 ∧ (tMin - 2) * (sl'.alloc - 1) + 2 * BTreeTree.potential tMin T' ≤ (tMin - 2) * (sl.alloc - 1) + 2 * BTreeTree.potential tMin T + 2 ∧ ValidSubtree true fpBits W_val tMin sl'.alloc sl'.nodes 0 (2 ^ fpBits - 1) (Function.update mapFn q (some val)) T'

Top-level subtree specification of btreeInsert on an already-initialized slice (1 ≤ alloc): increases height by at most 1 and excess-key split potential (tMin - 2) * (alloc - 1) + 2 * pot by at most 2.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidSubtree.node_bits_lt {isRoot : Bool} {metaBits fpBits W_val tMin alloc : ℕ} {nodes : ℕ → BTreeNode} {lo hi : ℕ} {mapFn : ℕ → Option ℕ} {T : BTreeTree} (ht1 : 1 ≤ tMin) (hmeta_cap : 4 * tMin ≤ 2 ^ metaBits) (hv : ValidSubtree isRoot fpBits W_val tMin alloc nodes lo hi mapFn T) (v : ℕ) :
v ∈ T.nodeSet → (nodes v).metaWord < 2 ^ metaBits ∧ (nodes v).keysWord < 2 ^ (2 * tMin * (fpBits + 2)) ∧ (nodes v).valsWord < 2 ^ (2 * tMin * W_val)

Every node inside a ValidSubtree automatically satisfies the packed bit-width bounds whenever 1 ≤ tMin and 4 * tMin ≤ 2 ^ metaBits.

Section 3: Concrete SuccinctWhpParams instantiation (ValidWhpSlice) #

Self-contained SuccinctWhp slice invariant coupling BTreeSlice (alloc = 0 empty or 1 ≤ alloc rooted ValidSubtree) with insertion count insCount at capacity n_max.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.validWhpSlice_zero (n_max insCount : ℕ) (nodes : ℕ → BTreeNode) :
ValidWhpSlice n_max insCount { alloc := 0, root := 0, nodes := nodes } fun (x : ℕ) => none

Unallocated slice (alloc = 0) satisfies ValidWhpSlice for the empty map.

64 ≤ nSliceWhp n_max unconditionally.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidWhpSlice.alloc_and_height_lt {c n_max insCount : ℕ} {sl : BTreeSlice} {mapFn : ℕ → Option ℕ} (hth : whpThreshold c ≤ n_max) (hins : insCount ≤ 8 * FeistelQuotient.slabScale n_max ^ 12) (hv : ValidWhpSlice n_max insCount sl mapFn) :
sl.alloc + hMaxBTree + 4 < nSliceWhp n_max ∧ ((sl.alloc = 0 ∧ mapFn = fun (x : ℕ) => none) ∨ 1 ≤ sl.alloc ∧ ∃ (T : BTreeTree), T.rootIdx = sl.root ∧ T.height < hMaxBTree ∧ (tMinWhp n_max - 2) * (sl.alloc - 1) + 2 * BTreeTree.potential (tMinWhp n_max) T ≤ 2 * insCount ∧ (∀ v ∈ T.nodeSet, (sl.nodes v).metaWord < 2 ^ nodeMetaBitsWhp n_max ∧ (sl.nodes v).keysWord < 2 ^ keysWordBitsWhp n_max ∧ (sl.nodes v).valsWord < 2 ^ valsWordBitsWhp n_max) ∧ ValidSubtree true (fpBitsWhp n_max) (valLaneBitsWhp n_max) (tMinWhp n_max) sl.alloc sl.nodes 0 (2 ^ fpBitsWhp n_max - 1) mapFn T)

Bounded allocation, height, and packed-word eliminator (ValidWhpSlice.alloc_and_height_lt): Whenever whpThreshold c ≤ n_max and insCount ≤ 8 * (slabScale n_max) ^ 12, any ValidWhpSlice n_max insCount sl mapFn has sl.alloc + hMaxBTree + 4 < nSliceWhp n_max and unpacks either to sl.alloc = 0 ∧ mapFn = fun _ => none or to a rooted ValidSubtree spine T of height < hMaxBTree whose nodes fit within (nodeMetaBitsWhp, keysWordBitsWhp, valsWordBitsWhp).

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidWhpSlice.lookup_eq {c n_max insCount q : ℕ} {sl : BTreeSlice} {mapFn : ℕ → Option ℕ} (hth : whpThreshold c ≤ n_max) (hins : insCount ≤ 8 * FeistelQuotient.slabScale n_max ^ 12) (hv : ValidWhpSlice n_max insCount sl mapFn) (hq : q < 2 ^ fpBitsWhp n_max) :
btreeLookup (fpBitsWhp n_max) (valLaneBitsWhp n_max) (tMinWhp n_max) sl q = mapFn q

Lookup on a ValidWhpSlice returns mapFn q for every q < 2 ^ fpBitsWhp n_max.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidWhpSlice.delete_spec {c n_max insCount q : ℕ} {sl : BTreeSlice} {mapFn : ℕ → Option ℕ} (hth : whpThreshold c ≤ n_max) (hins : insCount ≤ 8 * FeistelQuotient.slabScale n_max ^ 12) (hv : ValidWhpSlice n_max insCount sl mapFn) (hq : q < 2 ^ fpBitsWhp n_max) :
ValidWhpSlice n_max insCount (btreeDelete (fpBitsWhp n_max) (valLaneBitsWhp n_max) (tMinWhp n_max) sl q) (Function.update mapFn q none)

Deletion on a ValidWhpSlice preserves ValidWhpSlice at the same insCount.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidWhpSlice.update_spec {c n_max insCount q newVal : ℕ} {sl : BTreeSlice} {mapFn : ℕ → Option ℕ} (hth : whpThreshold c ≤ n_max) (hins : insCount ≤ 8 * FeistelQuotient.slabScale n_max ^ 12) (hv : ValidWhpSlice n_max insCount sl mapFn) (hq : q < 2 ^ fpBitsWhp n_max) (hval : newVal < 2 ^ valLaneBitsWhp n_max) :
ValidWhpSlice n_max insCount (btreeUpdate (fpBitsWhp n_max) (valLaneBitsWhp n_max) (tMinWhp n_max) sl q newVal) (if (mapFn q).isSome = true then Function.update mapFn q (some newVal) else mapFn)

In-place value update on a ValidWhpSlice preserves ValidWhpSlice at the same insCount.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidWhpSlice.insert_spec {c n_max insCount q val : ℕ} {sl : BTreeSlice} {mapFn : ℕ → Option ℕ} (hth : whpThreshold c ≤ n_max) (hins : insCount ≤ 8 * FeistelQuotient.slabScale n_max ^ 12) (hv : ValidWhpSlice n_max insCount sl mapFn) (hq : q < 2 ^ fpBitsWhp n_max) (hval : val < 2 ^ valLaneBitsWhp n_max) :
have sl' := btreeInsert (fpBitsWhp n_max) (valLaneBitsWhp n_max) (tMinWhp n_max) sl q val; sl'.alloc < nSliceWhp n_max ∧ ValidWhpSlice n_max (insCount + 1) sl' (Function.update mapFn q (some val))

Insertion on a ValidWhpSlice produces a ValidWhpSlice at insCount + 1 with alloc < nSliceWhp n_max.