Pure Deamortized WHP Succinct Dynamic Dictionary Model #
This module combines the SWAR B+-tree query mappers (SuccinctWhpSwarBTreeInsert), bounded-depth
character-trie collision buffers (SuccinctWhpBufferTrie), probabilistic window tail bounds
(SuccinctWhpProb), and small-regime / in-place CSR fallback primitives (SuccinctWhpFallback)
into the complete pure state-transition model (WhpDictState, whpInitPure, whpStepPure,
whpRunPure) of the with-high-probability fixed-capacity succinct dynamic dictionary
(Bender, Farach-Colton, J. Kuszmaul, and W. Kuszmaul, SOSA 2024,
Sections 3–5).
Architecture #
Three execution regimes (
WhpDictState):.small: whenn_max < whpThreshold c, usesSmallDictState(deterministic linear scan overn_max < whpThreshold cslots, zero failure probability)..fast: whenwhpThreshold c ≤ n_max, maintainsM = numBucketsWhp n_maxFeistel buckets with dense local coordinates0 .. bktCount b - 1(front-yard0 .. capFrontWhp - 1plus backyard pointersbackPtr b kbacked bypoolFreeStack/poolOwner), three orthogonal SWAR B+-tree slices per bucket (liveRole,overmarsRole,rebRole), and two epoch collision buffers (buf 0,buf 1) rotated everyqEpochWhp n_maxoperations across stages0 .. 5..fallback: rare compressed-sparse-row (CsrState) mode for adversarial seed collisions or load imbalance; at the end of every fallback operation,trySelfHealrunscheckGoodSeedOnStateand immediately restores.fastin place viapermuteByTargetwheneverGoodSeedOnStateholds.
Exact correctness for every seed + fast-branch hit under
GoodSeedOnWindow:whpStepPure_spec(inSuccinctWhpModelTick): for every static seedθand every admissible operationo,whpStepPurerefinesDynamic.stepwhile preservingValidWhpState.isFastStepHit_of_goodSeedOnWindow(inSuccinctWhpFastProb): wheneverwhpThreshold c ≤ n_maxandGoodSeedOnWindow c U n_max (ops ++ [o]) θholds after an admissible prefixopsof any length,whpRunPureis in.fastmode atopsandwhpStepPureexecutesoon the fast branch (fastStepPurereturnssome _).
Main definitions #
Cslib.DataStructure.Dictionary.SuccinctWhp.FastState,WhpDictState: pure fast-mode and combined dictionary states.Cslib.DataStructure.Dictionary.SuccinctWhp.fastQuery,fastInsert,fastDelete,overmarsStep,epochTick,fastStepPure: fast-branch operations and background deamortization ticks.Cslib.DataStructure.Dictionary.SuccinctWhp.fastToCsr,csrToFast,trySelfHeal: in-place mode transitions viapermuteByTarget.Cslib.DataStructure.Dictionary.SuccinctWhp.whpInitPure,whpStepPure,whpRunPure,OvermarsBucketInv,ValidFastState,ValidWhpState: top-level pure transitions and representation invariants.
Main results #
Cslib.DataStructure.Dictionary.SuccinctWhp.whpInitPure_spec: initial state validity.Cslib.DataStructure.Dictionary.SuccinctWhp.ValidFastState.fastFindLoc_spec,ValidFastState.fastQuery_spec: exact fast-mode coordinate and value lookup for all seeds.Cslib.DataStructure.Dictionary.SuccinctWhp.ValidFastState.fastToCsr_spec,trySelfHeal_spec,csrStepOp_spec: exact mode-conversion, self-healing, and fallback step specifications (full step and window theorems are proved inSuccinctWhpModelStepandSuccinctWhpModelTick).
References #
Section 1: FastState, WhpDictState, and fast-mode helper operations #
Total local coordinates per bucket capFrontWhp n_max + capBackWhp n_max.
Unallocated zero BTreeSlice (alloc = 0, root = 0, all-zero nodes).
Header-only slice reset (alloc := 0, root := 0, leaving nodes untouched).
Pure state of the fast mode (whpThreshold c ≤ n_max).
Stored Feistel quotients
< 2 ^ quotBitsWhp U n_maxacross0 .. n_max - 1.Stored values
< Vacross0 .. n_max - 1.Active item count
≤ totalLocalCoordsWhp n_maxin bucketb.Active fingerprint salt
< sMaxWhp c n_maxof bucketb.Role offset
∈ {0, 1, 2}of bucketb's live B+-tree slice (3 * b + liveRole b).Cumulative insertions into bucket
b's current live B+-tree slice.Role offset
∈ {0, 1, 2}of bucketb's Overmars shadow slice (3 * b + overmarsRole b).Whether Overmars per-bucket rebuild is active (
0or1) on bucketb.Next local coordinate to scan in bucket
b's Overmars rebuild.Cumulative insertions into bucket
b's Overmars shadow slice.Flag (
0or1) marking that dirty bucketbfinished Stage-2 rebuild in this epoch.Deduplication flag (
0or1) for dirty-bucket collection in Stage 1.Backyard pointer table mapping
(b, k)(k = loc - capFrontWhp) to< poolSizeWhp.- poolFreeTop : ℕ
Number of free slots on
poolFreeStack(≤ poolSizeWhp n_max). Stack of free backyard pool indices
< poolSizeWhp n_max.Reverse owner tag
b * capBackWhp n_max + kfor allocated pool slotpoolIdx.- slices : ℕ → BTreeSlice
Array of
3 * numBucketsWhp n_maxSWAR B+-tree slices. - curEp : ℕ
- epochClock : ℕ
Tick counter
0 .. qEpochWhp n_max - 1within the current epoch. - rebStage : ℕ
Global epoch rebuild stage (
0= reset flags,1= queue dirty buckets,2= rebuild dirty buckets,3= drainBufOld,4= clearBufOldnodes,5= idle until rotation). - stageCursor : ℕ
Cursor for Stages
0,1, and3(0 .. (buf oldEp).itemAlloc). - dirtyCount : ℕ
Number of deduplicated dirty buckets queued for Stage
2. Deduplicated dirty bucket indices
0 .. dirtyCount - 1.- dirtyIdx : ℕ
Index
0 .. dirtyCountof the dirty bucket currently being rebuilt in Stage2. - rebCandSalt : ℕ
Candidate salt
< sMaxWhp c n_maxcurrently being tested in Stage2. - rebScanCursor : ℕ
Local coordinate cursor for the current
(dirtyBuckets dirtyIdx, rebCandSalt)scan. - rebInsCount : ℕ
Cumulative insertions into the current
rebSlicescan. - rebCollision : ℕ
Collision flag (
0= collision-free so far,1= collision detected) in Stage2.
Combined pure state of the WHP succinct dynamic dictionary across all n_max.
- small (st : SmallDictState) : WhpDictState
- fast (fs : FastState) : WhpDictState
- fallback (csr : CsrState) : WhpDictState
Clean initial FastState (empty U: all counts 0, curEp = 0, epochClock = 0,
rebStage = 5, poolFreeStack i = i for i < poolSizeWhp n_max).
Old collision-buffer index 1 - fs.curEp.
Role offset 3 - liveRole b - overmarsRole b of bucket b's epoch-rebuild B+-tree slice.
Global slice index 3 * b + overmarsRole b of bucket b's Overmars shadow B+-tree.
Fast-mode coordinate lookup for u : Fin U: probes buf curEp, then buf oldEp, then
liveSlice[b], verifying (b, q_val) at the candidate slot so false positives are impossible for
every seed θ.
Section 2: Background Overmars rebuild, global epochTick, fastDelete, fastInsert #
Scan rem coordinates starting at fs.overmarsCursor b for bucket b's Overmars shadow
slice.
Activation substep of overmarsStep on bucket b.
Advance Overmars per-bucket shadow rebuild on bucket b by 16 coordinates (activating when
liveInsCount b ≥ 5 * (slabScale n_max) ^ 12, and swapping roles once overmarsCursor b ≥ bktCount b).
Scan rem coordinates starting at fs.rebScanCursor for Stage-2 bucket b under candidate
salt fs.rebCandSalt.
Stage 0 of epochTick: clear rebQueued and rebDoneFlag across oldTr's slots.
End-of-Stage-1 transition of epochTick: enter Stage 3 when dirtyCount = 0, otherwise
initialize Stage 2 on dirtyBuckets 0.
Stage 1 of epochTick: collect distinct dirty buckets from oldTr into dirtyBuckets.
Role swap at the end of a collision-free Stage-2 bucket scan for b.
Post-swap Stage-2 transition: advance to Stage 3 or reset the next dirty bucket's rebuild slice.
Post-scan decision of Stage 2 after rebScanSteps ... 16.
Stage 2 of epochTick: scan 16 coordinates of dirtyBuckets dirtyIdx under rebCandSalt.
Stage 4 of epochTick: clear up to 8 trie nodes of oldTr via bufClearSteps 8.
Combined Stage 0 .. 5 step of epochTick prior to epochClock rollover.
Advance epochClock after epochTickStage, flipping curEp at qEpochWhp n_max iff
rebStage = 5 and returning none otherwise.
Execute one global deamortization tick across Stages 0 .. 5 and advance epochClock
(returning none iff epochClock + 1 = qEpochWhp n_max while rebStage ≠ 5).
Substep 1 of fastDelete: remove (u, loc_del) from the epoch buffers and B+-tree slices.
Helper for fastDeleteMoveLast: relocate loc_last → loc_del in liveSlice and
overmarsSlice.
Substep 2 of fastDelete (when loc_del < loc_last): relocate loc_last into loc_del.
Substep 3 of fastDelete: clear loc_last, decrement bktCount b, and release any backyard
slot at loc_last.
Fast-mode deletion of u : Fin U, relocating loc_last = bktCount b - 1 into loc_del to
maintain dense coordinates 0 .. bktCount b - 1, followed by overmarsStep on bucket b.
Backyard pool allocation substep of fastInsert at coordinate (b, X).
Fresh-key insertion substep of fastInsert prior to overmarsStep.
Section 3: In-place fastToCsr, csrToFast, trySelfHeal, and whpStepPure #
Execute one operation on CsrState (query, delete, insert).
Initial state of the WHP succinct dynamic dictionary.
Single-operation deterministic transition of the WHP succinct dynamic dictionary for fixed seed
θ.
Execute a sequence of operations sequentially from pure state st.
Pure state reached from whpInitPure c n_max after running ops : List (Dynamic.Op U).
Section 4: ValidFastState, ValidWhpState, whpInitPure_spec, and fastQuery_spec #
Per-bucket Overmars shadow-rebuild invariant in ValidFastState.
Complete deterministic invariant of FastState valid for every static seed θ.
- hth : whpThreshold c ≤ n_max
- rebCollision_zero : fs.rebCollision = 0
- active_item (b : ℕ) : b < numBucketsWhp n_max → ∀ loc < fs.bktCount b, let kv := FastState.keyValAt c U n_max θ.1 fs b loc; kv < U ∧ FeistelQuotient.feistelBucket (bWhp n_max) (bktHash c U n_max θ.1) kv = b ∧ FeistelQuotient.keyQuotient (bWhp n_max) kv = fs.quotArr (FastState.physSlot n_max fs b loc) ∧ fs.valArr (FastState.physSlot n_max fs b loc) < V
- quot_inj (b : ℕ) : b < numBucketsWhp n_max → ∀ l₁ < fs.bktCount b, ∀ l₂ < fs.bktCount b, fs.quotArr (FastState.physSlot n_max fs b l₁) = fs.quotArr (FastState.physSlot n_max fs b l₂) → l₁ = l₂
- dict_map (u : Fin U) : let b := FeistelQuotient.feistelBucket (bWhp n_max) (bktHash c U n_max θ.1) ↑u; let q := FeistelQuotient.keyQuotient (bWhp n_max) ↑u; (dict u = none ↔ ∀ loc < fs.bktCount b, fs.quotArr (FastState.physSlot n_max fs b loc) ≠ q) ∧ ∀ (v : ℕ), dict u = some v ↔ ∃ loc < fs.bktCount b, fs.quotArr (FastState.physSlot n_max fs b loc) = q ∧ fs.valArr (FastState.physSlot n_max fs b loc) = v
- backPtr_valid (b : ℕ) : b < numBucketsWhp n_max → ∀ k < fs.bktCount b - capFrontWhp n_max, fs.backPtr b k < poolSizeWhp n_max ∧ fs.poolOwner (fs.backPtr b k) = b * capBackWhp n_max + k
- backPtr_inj (b₁ : ℕ) : b₁ < numBucketsWhp n_max → ∀ k₁ < fs.bktCount b₁ - capFrontWhp n_max, ∀ b₂ < numBucketsWhp n_max, ∀ k₂ < fs.bktCount b₂ - capFrontWhp n_max, fs.backPtr b₁ k₁ = fs.backPtr b₂ k₂ → b₁ = b₂ ∧ k₁ = k₂
- freeStack_inj (j₁ : ℕ) : j₁ < fs.poolFreeTop → ∀ j₂ < fs.poolFreeTop, fs.poolFreeStack j₁ = fs.poolFreeStack j₂ → j₁ = j₂
- back_free_disj (b : ℕ) : b < numBucketsWhp n_max → ∀ k < fs.bktCount b - capFrontWhp n_max, ∀ j < fs.poolFreeTop, fs.backPtr b k ≠ fs.poolFreeStack j
- pool_conservation : fs.poolFreeTop + ∑ b ∈ Finset.range (numBucketsWhp n_max), (fs.bktCount b - capFrontWhp n_max) = poolSizeWhp n_max
- roles_valid (b : ℕ) : b < numBucketsWhp n_max → fs.liveRole b < 3 ∧ fs.overmarsRole b < 3 ∧ fs.liveRole b ≠ fs.overmarsRole b
- live_fp_inj (b : ℕ) : b < numBucketsWhp n_max → ∀ l₁ < fs.bktCount b, ∀ l₂ < fs.bktCount b, inLiveTree fs.rebStage fs.oldEp (fs.rebDoneFlag b) (fs.locState b l₁) = true → inLiveTree fs.rebStage fs.oldEp (fs.rebDoneFlag b) (fs.locState b l₂) = true → FastState.fpAt c U n_max θ fs (fs.bktSalt b) b l₁ = FastState.fpAt c U n_max θ fs (fs.bktSalt b) b l₂ → l₁ = l₂
- live_valid (b : ℕ) : b < numBucketsWhp n_max → ∃ (liveMap : ℕ → Option ℕ), ValidWhpSlice n_max (fs.liveInsCount b) (fs.slices (fs.liveSliceIdx b)) liveMap ∧ SliceMapRel (FastState.fpAt c U n_max θ fs (fs.bktSalt b) b) (fun (loc : ℕ) => inLiveTree fs.rebStage fs.oldEp (fs.rebDoneFlag b) (fs.locState b loc) = true) (fs.bktCount b) liveMap
- rKey_buf_inj (b₁ : ℕ) : b₁ < numBucketsWhp n_max → ∀ l₁ < fs.bktCount b₁, ∀ b₂ < numBucketsWhp n_max, ∀ l₂ < fs.bktCount b₂, 2 ≤ fs.locState b₁ l₁ → 2 ≤ fs.locState b₂ l₂ → FastState.rKeyAt c U n_max θ fs b₁ l₁ = FastState.rKeyAt c U n_max θ fs b₂ l₂ → b₁ = b₂ ∧ l₁ = l₂
- bufCur_valid : (fs.buf fs.curEp).itemAlloc ≤ 2 * sMaxWhp c n_max ∧ (fs.buf fs.curEp).nodeAlloc ≤ 1 + cTabWhp c * (fs.buf fs.curEp).itemAlloc ∧ ∃ (curMap : ℕ → Option (ℕ × ℕ)), ValidBufTrie (cTabWhp c) (bCharWhp n_max) (fs.buf fs.curEp) curMap ∧ BufMapRel (numBucketsWhp n_max) (2 + fs.curEp) fs.bktCount fs.locState (FastState.rKeyAt c U n_max θ fs) curMap
- bufOld_valid : if fs.rebStage ≤ 3 then (fs.buf fs.oldEp).itemAlloc ≤ 2 * sMaxWhp c n_max ∧ (fs.buf fs.oldEp).nodeAlloc ≤ 1 + cTabWhp c * (fs.buf fs.oldEp).itemAlloc ∧ ∃ (oldMap : ℕ → Option (ℕ × ℕ)), ValidBufTrie (cTabWhp c) (bCharWhp n_max) (fs.buf fs.oldEp) oldMap ∧ BufMapRel (numBucketsWhp n_max) (2 + fs.oldEp) fs.bktCount fs.locState (FastState.rKeyAt c U n_max θ fs) oldMap else if fs.rebStage = 4 then (∀ b < numBucketsWhp n_max, ∀ loc < fs.bktCount b, fs.locState b loc ≠ 2 + fs.oldEp) ∧ ClearableBufTrie (fs.buf fs.oldEp) ∧ (fs.buf fs.oldEp).nodeAlloc ≤ 1 + cTabWhp c * (2 * sMaxWhp c n_max) else (∀ b < numBucketsWhp n_max, ∀ loc < fs.bktCount b, fs.locState b loc ≠ 2 + fs.oldEp) ∧ (ValidBufTrie (cTabWhp c) (bCharWhp n_max) (fs.buf fs.oldEp) fun (x : ℕ) => none) ∧ (fs.buf fs.oldEp).nodeAlloc = 1 ∧ (fs.buf fs.oldEp).itemAlloc = 0
- stage_valid : ValidEpochStage c U n_max θ fs
Combined representation invariant for WhpDictState across all n_max.
whpInitPure satisfies ValidWhpState for Dictionary.empty U.
Exact soundness and completeness of fastFindLoc for every seed θ:
- If
fastFindLocreturnssome loc, thenloc < fs.bktCount bandquotArr (physSlot b loc) = keyQuotient u.val; - If
fastFindLocreturnsnone, thendict u = none.
fastQuery returns dict u for every seed θ whenever ValidFastState holds.
Section 5: Mode transitions (fastToCsr_spec, csrToFast_spec, trySelfHeal_spec) #
Physical slot < n_max and injectivity for any ValidFastState.
fastToCsr converts any ValidFastState into a ValidCsrState preserving global (q, v)
bounds.
trySelfHeal preserves ValidWhpState and, whenever GoodSeedOnState c U n_max θ dict holds,
produces a clean .fast state (Buf[0] = emptyBufTrie, Buf[1] = emptyBufTrie, epochClock = 0,
rebStage = 5).
Convert dependent op.Result into homogeneous Option ℕ (some/none for .query, none
for updates).
csrStepOp preserves ValidCsrState and global (q, v) bounds while refining
Dynamic.step.