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 (+, -, *, /, %, &&&, |||, ^^^,
<<<, >>>):
- SWAR parallel rank (
swarRank_eq_count_lt): packingm < 2 * tMinkeys into lanes of widthW_lane = fpBits + 2inside a single< 2 ^ ⌊log₂ n_max⌋word, borrow-free parallel subtraction and multiplication byswarOnescount# { j < m | k_j < q }inO(1)word operations. - Top-down proactive splitting and lazy deletion: proactive root-to-leaf splitting of full
(
2 * tMin - 1-key) nodes viasplitFullNode(NodeSplit) maintains strict separator intervals(s_{j-1}, s_j]without bottom-up backtracking, whilebtreeDeleteremoves keys directly from leaves viawordDeleteAtwith zero sibling borrows or merges. The excess-key split potential (BTreeTree.potential) bounds total allocated nodes afterIinsertions (and arbitrarily many deletions) by1 + 2 * I / (tMin - 2) < nSliceWhp, and branching≥ tMinbounds tree height byhMaxBTree = 42.
Main definitions #
Cslib.DataStructure.Dictionary.SuccinctWhp.wordTakeLow,wordDropLow,wordInsertAt,wordDeleteAt,wordUpdateAt,swarOnes,ltMask,swarRank: pure SWAR lane update and parallel-rank operations (built onCslib.DataStructure.laneGetinCslibFrontier/DataStructure/PackedLane.lean).Cslib.DataStructure.Dictionary.SuccinctWhp.BTreeNode,NodeSplit,BTreeSlice,splitFullNode,finishLeafInsert,btreeLookup,btreeInsert,btreeDelete,btreeUpdate,hMaxBTree: pure bounded-depth top-down split-only SWAR B+-tree operations.
Main results #
Cslib.DataStructure.Dictionary.SuccinctWhp.swarRank_eq_count_lt: exact equality betweenswarRankand#((Finset.range m).filter fun j => laneGet W keysWord j < q).Cslib.DataStructure.Dictionary.SuccinctWhp.ValidSubtree.frame: frame invariance ofValidSubtreeunder updates outsideT.nodeSet.Cslib.DataStructure.Dictionary.SuccinctWhp.ValidSubtree.two_mul_pow_height_sub_one_le_leafCount: branching lower bound2 * tMin ^ (T.height - 1) ≤ T.leafCountfor every valid subtree of height≥ 1.
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.
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.
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.
swarOnes, ltMask, and swarRank_eq_count_lt #
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.
Explicit numerical value hMaxBTree = 42.
Extract isLeaf from metaWord.
Extract keyCount from metaWord.
metaIsLeaf recovers the isLeaf flag packed by mkNodeMeta.
metaCount recovers the key count packed by mkNodeMeta.
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).
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.
Split a full (2 * tMin - 1-key) node nd into ⟨left, sep, right⟩ under the
(s_{j-1}, s_j] interval convention:
- If
ndis a leaf:leftkeeps the lowtMinentries (0 .. tMin - 1),sepisk_{tMin - 1}, andrightkeeps the hightMin - 1entries (tMin .. 2 * tMin - 2). - If
ndis internal:leftkeepstMin - 1separators (0 .. tMin - 2) andtMinchildren (0 .. tMin - 1),sepiss_{tMin - 1}, andrightkeepstMin - 1separators (tMin .. 2 * tMin - 2) andtMinchildren (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 #
Root node index of T.
Height of T (0 for a leaf).
Set of physical slice node indices occupied by T.
Number of leaves in 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].
When the sorted separator keys in keysWord start at ≥ lo, every child r ≤ cnt has
lo ≤ childLo W_key lo keysWord r.
When the sorted separator keys in keysWord end at ≤ hi, every index r has
childHi W_key hi cnt keysWord r ≤ hi.
Frame invariance of ValidSubtree under updates outside T.nodeSet and monotone alloc.
Every node in T.nodeSet is strictly below alloc, and T.leafCount ≤ #T.nodeSet ≤ alloc.
A valid subtree occupies at most alloc physical slice nodes.
Any valid subtree of height ≥ 1 has 2 * tMin ^ (T.height - 1) ≤ T.leafCount.