Documentation

CslibFrontier.DataStructure.Dictionary.SuccinctWhpSwarBTree

SWAR Parallel Word-Lane Rank and Top-Down Split-Only B+-Tree Query-Mapper #

This module formalizes the pure word-level SWAR (SIMD Within A Register) lane operations and the bounded-height top-down split-only B+-tree used as the intra-bucket fingerprint query-mapper in the with-high-probability succinct dynamic dictionary.

Original adaptation vs. SOSA 2024 Section 4 #

In Bender, Farach-Colton, J. Kuszmaul, and W. Kuszmaul, SOSA 2024, Section 4, Lemma 4.2, pp. 363–373; author copy p. 5, each bucket's query-mapper is a B = √(log n) B-tree navigated via exhaustive Four-Russians subtabulation lookup tables. Here we replace the Four-Russians table with an original SWAR top-down split-only B+-tree using only standard arithmetic and bitwise word operations (+, -, *, /, %, &&&, |||, ^^^, <<<, >>>):

  1. SWAR parallel rank (swarRank_eq_count_lt): packing m < 2 * tMin keys into lanes of width W_lane = fpBits + 2 inside a single < 2 ^ ⌊log₂ n_max⌋ word, borrow-free parallel subtraction and multiplication by swarOnes count # { j < m | k_j < q } in O(1) word operations.
  2. Top-down proactive splitting and lazy deletion: proactive root-to-leaf splitting of full (2 * tMin - 1-key) nodes via splitFullNode (NodeSplit) maintains strict separator intervals (s_{j-1}, s_j] without bottom-up backtracking, while btreeDelete removes keys directly from leaves via wordDeleteAt with zero sibling borrows or merges. The excess-key split potential (BTreeTree.potential) bounds total allocated nodes after I insertions (and arbitrarily many deletions) by 1 + 2 * I / (tMin - 2) < nSliceWhp, and branching ≥ tMin bounds tree height by hMaxBTree = 42.

Main definitions #

Main results #

References #

Section 1: Pure SWAR word-lane operations and parallel rank #

Retain the low j lanes (j * W bits) of word.

Drop the low j lanes (j * W bits) of word.

Insert W-bit value v at lane j, shifting lanes ≥ j up by one lane.

Delete lane j, shifting lanes ≥ j + 1 down by one lane.

Overwrite lane j with W-bit value v.

Closed-form mask ∑_{j < n} 2 ^ (j * W) = (2 ^ (n * W) - 1) / (2 ^ W - 1).

Borrow-free parallel < q lane indicator mask across m lanes of width fpBits + 2.

def Cslib.DataStructure.Dictionary.SuccinctWhp.swarRank (fpBits capLanes m q keysWord : ℕ) :

Word-parallel SWAR rank # { j < m | laneGet (fpBits + 2) keysWord j < q }.

Modulus characterization of wordTakeLow.

Retaining the low j lanes produces a word < 2 ^ (j * W).

Division characterization of wordDropLow.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.wordDropLow_lt {W a b word : ℕ} (hw : word < 2 ^ ((a + b) * W)) :
wordDropLow W a word < 2 ^ (b * W)

Dropping the low a lanes of a word < 2 ^ ((a + b) * W) produces a word < 2 ^ (b * W).

Lane extraction from wordTakeLow returns laneGet W word i for i < j and 0 otherwise.

Lane i of wordDropLow W j word equals lane j + i of word.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.laneGet_wordInsertAt {W j v word : ℕ} (hv : v < 2 ^ W) (i : ℕ) :
laneGet W (wordInsertAt W j v word) i = if i < j then laneGet W word i else if i = j then v else laneGet W word (i - 1)

Lane extraction after inserting v < 2 ^ W at lane j.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.laneGet_wordDeleteAt (W j word i : ℕ) :
laneGet W (wordDeleteAt W j word) i = if i < j then laneGet W word i else laneGet W word (i + 1)

Lane extraction after deleting lane j.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.laneGet_wordUpdateAt {W j v word : ℕ} (hv : v < 2 ^ W) (i : ℕ) :
laneGet W (wordUpdateAt W j v word) i = if i = j then v else laneGet W word i

Lane extraction after overwriting lane j with v < 2 ^ W.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.wordInsertAt_lt {W j m v word : ℕ} (hj : j ≤ m) (hv : v < 2 ^ W) (hw : word < 2 ^ (m * W)) :
wordInsertAt W j v word < 2 ^ ((m + 1) * W)

Inserting v < 2 ^ W at lane j ≤ m of a word < 2 ^ (m * W) produces a word < 2 ^ ((m + 1) * W).

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.wordDeleteAt_lt {W j m word : ℕ} (hj : j ≤ m) (hw : word < 2 ^ ((m + 1) * W)) :
wordDeleteAt W j word < 2 ^ (m * W)

Deleting lane j ≤ m of a word < 2 ^ ((m + 1) * W) produces a word < 2 ^ (m * W).

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.wordUpdateAt_lt {W j m v word : ℕ} (hj : j < m) (hv : v < 2 ^ W) (hw : word < 2 ^ (m * W)) :
wordUpdateAt W j v word < 2 ^ (m * W)

Overwriting lane j < m with v < 2 ^ W preserves the < 2 ^ (m * W) bound.

swarOnes, ltMask, and swarRank_eq_count_lt #

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.swarOnes_eq_sum {W : ℕ} (hW : 1 ≤ W) (n : ℕ) :
swarOnes W n = ∑ j ∈ Finset.range n, 2 ^ (j * W)
theorem Cslib.DataStructure.Dictionary.SuccinctWhp.swarRank_eq_count_lt {fpBits capLanes m q keysWord : ℕ} (hm : m < capLanes) (hcap : capLanes < 2 ^ (fpBits + 2)) (hq : q < 2 ^ fpBits) (hkw : keysWord < 2 ^ (m * (fpBits + 2))) (hlanes : ∀ j < m, laneGet (fpBits + 2) keysWord j < 2 ^ fpBits) :
swarRank fpBits capLanes m q keysWord = {j ∈ Finset.range m | laneGet (fpBits + 2) keysWord j < q}.card

Exact SWAR parallel rank theorem: whenever m < capLanes, capLanes < 2 ^ (fpBits + 2), q < 2 ^ fpBits, keysWord < 2 ^ (m * (fpBits + 2)), and every lane j < m satisfies laneGet (fpBits + 2) keysWord j < 2 ^ fpBits, swarRank equals the exact count of lanes < m strictly smaller than q.

Section 2: Iterative Top-Down Split-Only SWAR B+-Tree #

Worst-case height bound 42 for any SWAR B+-tree slice at whpThreshold c ≤ n_max with at most 8 * (slabScale n_max) ^ 12 insertions (2 * tMin ^ 41 > nSliceWhp n_max since slabScale ≤ tMin ^ 3). Kept opaque across module boundaries (with hMaxBTree_eq) so symbolic proofs do not unfold 42 recursion steps in the kernel.

Packed representation of a single SWAR B+-tree node (metaWord = isLeafBit + 2 * keyCount, keysWord, valsWord).

  • metaWord : ℕ

    Packed isLeaf bit (metaWord % 2) and key count (metaWord / 2).

  • keysWord : ℕ

    Packed sorted W_key-bit fingerprint lanes.

  • valsWord : ℕ

    Packed W_val-bit value lanes (for leaves) or child node indices (for internal nodes).

Pack (isLeaf, keyCount) into metaWord.

@[simp]

metaIsLeaf recovers the isLeaf flag packed by mkNodeMeta.

@[simp]

metaCount recovers the key count packed by mkNodeMeta.

Pure state of a single SWAR B+-tree slice (alloc allocated nodes 0 .. alloc - 1, root index, and node map nodes).

  • alloc : ℕ

    Number of allocated nodes (0 denotes an uninitialized empty slice).

  • root : ℕ

    Root node index (< alloc when 0 < alloc).

  • nodes : ℕ → BTreeNode

    Node array indexed by 0 .. alloc - 1.

Empty initialized 1-leaf BTreeSlice (alloc = 1, root = 0, empty leaf at 0).

Ensure a slice has at least its initial empty root leaf allocated (alloc = 0 ↦ emptyBTreeSlice in 1 node write at index 0).

def Cslib.DataStructure.Dictionary.SuccinctWhp.descendToLeaf (fpBits W_val tMin : ℕ) (nodes : ℕ → BTreeNode) :
ℕ → ℕ → ℕ → ℕ

Bounded root-to-leaf descent finding the leaf node containing interval q.

Pure SWAR B+-tree lookup of fingerprint q < 2 ^ fpBits.

Pure SWAR B+-tree lazy leaf deletion of fingerprint q (0 node allocations, no borrows).

Pure SWAR B+-tree in-place value update for an existing fingerprint q.

Output record of splitting a full (2 * tMin - 1-key) BTreeNode into a left node, promoted separator key, and right node.

  • left : BTreeNode

    Left split node covering keys ≤ sep.

  • sep : ℕ

    Promoted separator key s_{tMin - 1}.

  • right : BTreeNode

    Right split node covering keys > sep.

Split a full (2 * tMin - 1-key) node nd into ⟨left, sep, right⟩ under the (s_{j-1}, s_j] interval convention:

  • If nd is a leaf: left keeps the low tMin entries (0 .. tMin - 1), sep is k_{tMin - 1}, and right keeps the high tMin - 1 entries (tMin .. 2 * tMin - 2).
  • If nd is internal: left keeps tMin - 1 separators (0 .. tMin - 2) and tMin children (0 .. tMin - 1), sep is s_{tMin - 1}, and right keeps tMin - 1 separators (tMin .. 2 * tMin - 2) and tMin children (tMin .. 2 * tMin - 1).

Proactive root split if sl.root has 2 * tMin - 1 keys: allocates leftIdx = sl.alloc and rightIdx = sl.alloc + 1, updating sl.root in place to the 1-separator internal root.

Bounded top-down proactive-splitting descent from a non-full node cur to the target non-full leaf for q.

Leaf insertion/overwrite post-step of btreeInsert.

Pure top-down split-only SWAR B+-tree insertion (or in-place value overwrite if q is already present).

Section 3: Algebraic spine BTreeTree, ValidSubtree, and excess-key split potential #

Pure inductive spine witnessing the tree structure of a BTreeSlice.

Set of physical slice node indices occupied by T.

Excess-key split potential ∑_{v ∈ T} (keyCount v - (tMin - 1)).

Left interval endpoint for child r of an internal node on [lo, hi] with keysWord.

Right interval endpoint for child r of an internal node with cnt separators on [lo, hi].

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.le_childLo {W_key lo cnt keysWord r : ℕ} (hr : r ≤ cnt) (hlo0 : lo ≤ laneGet W_key keysWord 0) (hmono : ∀ (i j : ℕ), i < j → j < cnt → laneGet W_key keysWord i < laneGet W_key keysWord j) :
lo ≤ childLo W_key lo keysWord r

When the sorted separator keys in keysWord start at ≥ lo, every child r ≤ cnt has lo ≤ childLo W_key lo keysWord r.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.childHi_le {W_key hi cnt keysWord r : ℕ} (hhi_last : laneGet W_key keysWord (cnt - 1) ≤ hi) (hmono : ∀ (i j : ℕ), i < j → j < cnt → laneGet W_key keysWord i < laneGet W_key keysWord j) :
childHi W_key hi cnt keysWord r ≤ hi

When the sorted separator keys in keysWord end at ≤ hi, every index r has childHi W_key hi cnt keysWord r ≤ hi.

def Cslib.DataStructure.Dictionary.SuccinctWhp.ValidSubtree (isRoot : Bool) (fpBits W_val tMin alloc : ℕ) (nodes : ℕ → BTreeNode) (lo hi : ℕ) (mapFn : ℕ → Option ℕ) :

Structural, ordering, disjointness, equal-depth, and map-refinement invariant for a subtree T covering keys in [lo, hi].

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidSubtree.frame {isRoot : Bool} {fpBits W_val tMin alloc alloc' : ℕ} {nodes nodes' : ℕ → BTreeNode} {lo hi : ℕ} {mapFn mapFn' : ℕ → Option ℕ} {T : BTreeTree} (hv : ValidSubtree isRoot fpBits W_val tMin alloc nodes lo hi mapFn T) (halloc : alloc ≤ alloc') (hnodes : ∀ v ∈ T.nodeSet, nodes' v = nodes v) (hmap : ∀ (q : ℕ), lo ≤ q → q ≤ hi → mapFn' q = mapFn q) :
ValidSubtree isRoot fpBits W_val tMin alloc' nodes' lo hi mapFn' T

Frame invariance of ValidSubtree under updates outside T.nodeSet and monotone alloc.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidSubtree.leafCount_le_card_nodeSet {isRoot : Bool} {fpBits W_val tMin alloc : ℕ} {nodes : ℕ → BTreeNode} {lo hi : ℕ} {mapFn : ℕ → Option ℕ} {T : BTreeTree} (hv : ValidSubtree isRoot fpBits W_val tMin alloc nodes lo hi mapFn T) :
(∀ v ∈ T.nodeSet, v < alloc) ∧ T.leafCount ≤ T.nodeSet.card

Every node in T.nodeSet is strictly below alloc, and T.leafCount ≤ #T.nodeSet ≤ alloc.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidSubtree.card_nodeSet_le_alloc {isRoot : Bool} {fpBits W_val tMin alloc : ℕ} {nodes : ℕ → BTreeNode} {lo hi : ℕ} {mapFn : ℕ → Option ℕ} {T : BTreeTree} (hv : ValidSubtree isRoot fpBits W_val tMin alloc nodes lo hi mapFn T) :
T.nodeSet.card ≤ alloc

A valid subtree occupies at most alloc physical slice nodes.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.BTreeTree.height_branch_of_eq {idx cnt : ℕ} {cs : Fin (cnt + 1) → BTreeTree} (hht : ∀ (i : Fin (cnt + 1)), (cs i).height = (cs ⟨0, ⋯⟩).height) :
(branch idx cnt cs).height = 1 + (cs ⟨0, ⋯⟩).height

For any branch whose children all share (cs 0).height, height = 1 + (cs 0).height.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidSubtree.two_mul_pow_height_sub_one_le_leafCount {isRoot : Bool} {fpBits W_val tMin alloc : ℕ} {nodes : ℕ → BTreeNode} {lo hi : ℕ} {mapFn : ℕ → Option ℕ} {T : BTreeTree} (ht2 : 2 ≤ tMin) (hH : 1 ≤ T.height) (hv : ValidSubtree isRoot fpBits W_val tMin alloc nodes lo hi mapFn T) :
2 * tMin ^ (T.height - 1) ≤ T.leafCount

Any valid subtree of height ≥ 1 has 2 * tMin ^ (T.height - 1) ≤ T.leafCount.