Documentation

CslibFrontier.DataStructure.Dictionary.SuccinctWhpModel

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 #

  1. Three execution regimes (WhpDictState):

    • .small: when n_max < whpThreshold c, uses SmallDictState (deterministic linear scan over n_max < whpThreshold c slots, zero failure probability).
    • .fast: when whpThreshold c ≤ n_max, maintains M = numBucketsWhp n_max Feistel buckets with dense local coordinates 0 .. bktCount b - 1 (front-yard 0 .. capFrontWhp - 1 plus backyard pointers backPtr b k backed by poolFreeStack/poolOwner), three orthogonal SWAR B+-tree slices per bucket (liveRole, overmarsRole, rebRole), and two epoch collision buffers (buf 0, buf 1) rotated every qEpochWhp n_max operations across stages 0 .. 5.
    • .fallback: rare compressed-sparse-row (CsrState) mode for adversarial seed collisions or load imbalance; at the end of every fallback operation, trySelfHeal runs checkGoodSeedOnState and immediately restores .fast in place via permuteByTarget whenever GoodSeedOnState holds.
  2. Exact correctness for every seed + fast-branch hit under GoodSeedOnWindow:

    • whpStepPure_spec (in SuccinctWhpModelTick): for every static seed θ and every admissible operation o, whpStepPure refines Dynamic.step while preserving ValidWhpState.
    • isFastStepHit_of_goodSeedOnWindow (in SuccinctWhpFastProb): whenever whpThreshold c ≤ n_max and GoodSeedOnWindow c U n_max (ops ++ [o]) θ holds after an admissible prefix ops of any length, whpRunPure is in .fast mode at ops and whpStepPure executes o on the fast branch (fastStepPure returns some _).

Main definitions #

Main results #

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).

  • quotArr : ℕ → ℕ

    Stored Feistel quotients < 2 ^ quotBitsWhp U n_max across 0 .. n_max - 1.

  • valArr : ℕ → ℕ

    Stored values < V across 0 .. n_max - 1.

  • locState : ℕ → ℕ → ℕ

    Per-coordinate location tag ∈ {0, 1, 2, 3} (0 = free, 1 = live B+-tree only, 2 = in buf 0, 3 = in buf 1).

  • bktCount : ℕ → ℕ

    Active item count ≤ totalLocalCoordsWhp n_max in bucket b.

  • bktSalt : ℕ → ℕ

    Active fingerprint salt < sMaxWhp c n_max of bucket b.

  • liveRole : ℕ → ℕ

    Role offset ∈ {0, 1, 2} of bucket b's live B+-tree slice (3 * b + liveRole b).

  • liveInsCount : ℕ → ℕ

    Cumulative insertions into bucket b's current live B+-tree slice.

  • overmarsRole : ℕ → ℕ

    Role offset ∈ {0, 1, 2} of bucket b's Overmars shadow slice (3 * b + overmarsRole b).

  • overmarsActive : ℕ → ℕ

    Whether Overmars per-bucket rebuild is active (0 or 1) on bucket b.

  • overmarsCursor : ℕ → ℕ

    Next local coordinate to scan in bucket b's Overmars rebuild.

  • overmarsInsCount : ℕ → ℕ

    Cumulative insertions into bucket b's Overmars shadow slice.

  • rebDoneFlag : ℕ → ℕ

    Flag (0 or 1) marking that dirty bucket b finished Stage-2 rebuild in this epoch.

  • rebQueued : ℕ → ℕ

    Deduplication flag (0 or 1) for dirty-bucket collection in Stage 1.

  • backPtr : ℕ → ℕ → ℕ

    Backyard pointer table mapping (b, k) (k = loc - capFrontWhp) to < poolSizeWhp.

  • poolFreeTop : ℕ

    Number of free slots on poolFreeStack (≤ poolSizeWhp n_max).

  • poolFreeStack : ℕ → ℕ

    Stack of free backyard pool indices < poolSizeWhp n_max.

  • poolOwner : ℕ → ℕ

    Reverse owner tag b * capBackWhp n_max + k for allocated pool slot poolIdx.

  • slices : ℕ → BTreeSlice

    Array of 3 * numBucketsWhp n_max SWAR B+-tree slices.

  • buf : ℕ → BufTrie

    Two epoch collision buffers (buf 0 and buf 1).

  • curEp : ℕ

    Current active collision-buffer index (0 or 1; oldEp = 1 - curEp).

  • epochClock : ℕ

    Tick counter 0 .. qEpochWhp n_max - 1 within the current epoch.

  • rebStage : ℕ

    Global epoch rebuild stage (0 = reset flags, 1 = queue dirty buckets, 2 = rebuild dirty buckets, 3 = drain BufOld, 4 = clear BufOld nodes, 5 = idle until rotation).

  • stageCursor : ℕ

    Cursor for Stages 0, 1, and 3 (0 .. (buf oldEp).itemAlloc).

  • dirtyCount : ℕ

    Number of deduplicated dirty buckets queued for Stage 2.

  • dirtyBuckets : ℕ → ℕ

    Deduplicated dirty bucket indices 0 .. dirtyCount - 1.

  • dirtyIdx : ℕ

    Index 0 .. dirtyCount of the dirty bucket currently being rebuilt in Stage 2.

  • rebCandSalt : ℕ

    Candidate salt < sMaxWhp c n_max currently being tested in Stage 2.

  • rebScanCursor : ℕ

    Local coordinate cursor for the current (dirtyBuckets dirtyIdx, rebCandSalt) scan.

  • rebInsCount : ℕ

    Cumulative insertions into the current rebSlice scan.

  • rebCollision : ℕ

    Collision flag (0 = collision-free so far, 1 = collision detected) in Stage 2.

Combined pure state of the WHP succinct dynamic dictionary across all n_max.

Clean initial FastState (empty U: all counts 0, curEp = 0, epochClock = 0, rebStage = 5, poolFreeStack i = i for i < poolSizeWhp n_max).

If fs.curEp ∈ {0, 1}, then fs.oldEp ∈ {0, 1}.

Role offset 3 - liveRole b - overmarsRole b of bucket b's epoch-rebuild B+-tree slice.

Global slice index 3 * b + liveRole b of bucket b's live B+-tree.

Global slice index 3 * b + overmarsRole b of bucket b's Overmars shadow B+-tree.

Global slice index 3 * b + rebRole b of bucket b's epoch-rebuild B+-tree.

Physical (quotArr, valArr) index < n_max corresponding to (b, loc) in fs.

def Cslib.DataStructure.Dictionary.SuccinctWhp.FastState.keyValAt (c U n_max : ℕ) (θ₁ : BktSeed c U n_max) (fs : FastState) (b loc : ℕ) :

Reconstructed universe key feistelReconstruct b (quotArr (physSlot b loc)) at (b, loc).

def Cslib.DataStructure.Dictionary.SuccinctWhp.FastState.rKeyAt (c U n_max : ℕ) (θ : SeedWhp c U n_max) (fs : FastState) (b loc : ℕ) :

Reduced key fpReducedKey θ₂ at (b, loc) (or 0 if out of range).

def Cslib.DataStructure.Dictionary.SuccinctWhp.FastState.fpAt (c U n_max : ℕ) (θ : SeedWhp c U n_max) (fs : FastState) (salt b loc : ℕ) :

Salted fingerprint fpHash θ₂ salt at (b, loc) (or 0 if out of range).

def Cslib.DataStructure.Dictionary.SuccinctWhp.fpOfSalt (c U n_max : ℕ) (θ₂ : FpSeed c U n_max) (salt : ℕ) (u : Fin U) :

Salted fingerprint of key u : Fin U at salt (0 if salt ≥ sMaxWhp).

Whether an active coordinate with tag st = locState b loc currently resides in liveSlice[b]: either st = 1, or st = 2 + oldEp after bucket b has already swapped in its rebuilt slice in Stage 2 (rebStage = 2 ∧ rebDoneB = 1) or during Stage 3 (rebStage = 3).

Verify whether candidate (b_cand, loc) holds an active item of bucket b with quotient q_val.

def Cslib.DataStructure.Dictionary.SuccinctWhp.fastFindLoc (c U n_max : ℕ) (θ : SeedWhp c U n_max) (fs : FastState) (u : Fin U) :

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 θ.

def Cslib.DataStructure.Dictionary.SuccinctWhp.fastQuery (c U n_max : ℕ) (θ : SeedWhp c U n_max) (fs : FastState) (u : Fin U) :

Fast-mode value query for u : Fin U.

Section 2: Background Overmars rebuild, global epochTick, fastDelete, fastInsert #

Scan rem coordinates starting at fs.overmarsCursor b for bucket b's Overmars shadow slice.

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.

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.

Stage 2 of epochTick: scan 16 coordinates of dirtyBuckets dirtyIdx under rebCandSalt.

Stage 3 of epochTick: untag one item from oldTr (locState := 1) and delete its key.

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).

def Cslib.DataStructure.Dictionary.SuccinctWhp.fastDeleteRemove (c U n_max : ℕ) (θ : SeedWhp c U n_max) (fs : FastState) (u : Fin U) (b loc_del : ℕ) :

Substep 1 of fastDelete: remove (u, loc_del) from the epoch buffers and B+-tree slices.

def Cslib.DataStructure.Dictionary.SuccinctWhp.fastDeleteMoveSlices (n_max b loc_del loc_last fp_live_last : ℕ) (fs1 : FastState) :
(ℕ → BTreeSlice) × (ℕ → ℕ)

Helper for fastDeleteMoveLast: relocate loc_last → loc_del in liveSlice and overmarsSlice.

def Cslib.DataStructure.Dictionary.SuccinctWhp.fastDeleteMoveLast (c U n_max : ℕ) (θ : SeedWhp c U n_max) (b loc_del loc_last : ℕ) (rebActiveB : Bool) (fs1 : FastState) :

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.

def Cslib.DataStructure.Dictionary.SuccinctWhp.fastDelete (c U n_max : ℕ) (θ : SeedWhp c U n_max) (fs : FastState) (u : Fin U) :

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).

def Cslib.DataStructure.Dictionary.SuccinctWhp.fastInsertFresh (c n_max b X q_val v rKey fp lIdx : ℕ) (hasFpCollision : Bool) (fsAlloc : FastState) :

Fresh-key insertion substep of fastInsert prior to overmarsStep.

def Cslib.DataStructure.Dictionary.SuccinctWhp.fastInsert (c U n_max : ℕ) (θ : SeedWhp c U n_max) (fs : FastState) (u : Fin U) (v : ℕ) :

Fast-mode insertion / overwrite of (u, v), returning none iff a capacity, backyard-pool, Stage-1 rKey collision, or epoch collision-buffer cap guard fires.

Combined fast-branch step (foreground op + epochTick), returning none iff a fallback guard fires.

Section 3: In-place fastToCsr, csrToFast, trySelfHeal, and whpStepPure #

Prefix sums 0, bktCount 0, bktCount 0 + bktCount 1, … up to M.

Convert FastState in place via permuteByTarget into an equivalent CsrState.

Prefix sums of backyard excesses ∑_{b' < k} ((fbStart (b' + 1) - fbStart b') - capFront).

def Cslib.DataStructure.Dictionary.SuccinctWhp.buildBucketSlice (c U n_max : ℕ) (θ : SeedWhp c U n_max) (quotArr : ℕ → ℕ) (backPtr : ℕ → ℕ → ℕ) (b salt : ℕ) :

Build a fresh BTreeSlice for bucket b inserting coordinates 0 .. rem - 1 under salt.

def Cslib.DataStructure.Dictionary.SuccinctWhp.csrToFast (c U n_max : ℕ) (θ : SeedWhp c U n_max) (csr : CsrState) (salts : ℕ → ℕ) :

Convert CsrState in place via permuteByTarget into a clean FastState using verified collision-free salts.

Execute one operation on CsrState (query, delete, insert).

Check GoodSeedOnState on csr; if true, immediately self-heal into .fast, else remain in .fallback.

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).

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.whpRunFrom_append (c U n_max : ℕ) (θ : SeedWhp c U n_max) (st : WhpDictState) (l₁ l₂ : List (Dynamic.Op U)) :
whpRunFrom c U n_max θ st (l₁ ++ l₂) = whpRunFrom c U n_max θ (whpRunFrom c U n_max θ st l₁) l₂

Section 4: ValidFastState, ValidWhpState, whpInitPure_spec, and fastQuery_spec #

Relational map characterization for a BTreeSlice indexing {loc < X | P loc} under f.

def Cslib.DataStructure.Dictionary.SuccinctWhp.BufMapRel (M tag : ℕ) (bktCnt : ℕ → ℕ) (locSt rKeyOf : ℕ → ℕ → ℕ) (m : ℕ → Option (ℕ × ℕ)) :

Relational map characterization for a BufTrie indexing {b < M, loc < bktCnt b | locSt = tag} under rKeyOf.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.SliceMapRel.empty_of_not (f : ℕ → ℕ) (P : ℕ → Prop) (X : ℕ) (hnone : ∀ loc < X, ¬P loc) :
SliceMapRel f P X fun (x : ℕ) => none
theorem Cslib.DataStructure.Dictionary.SuccinctWhp.BufMapRel.empty_of_not (M tag : ℕ) (bktCnt : ℕ → ℕ) (locSt rKeyOf : ℕ → ℕ → ℕ) (hnone : ∀ b < M, ∀ loc < bktCnt b, locSt b loc ≠ tag) :
BufMapRel M tag bktCnt locSt rKeyOf fun (x : ℕ) => none

Global epoch stage invariant across Stages 0 .. 5.

Per-bucket Overmars shadow-rebuild invariant in ValidFastState.

structure Cslib.DataStructure.Dictionary.SuccinctWhp.ValidFastState (c U V n_max : ℕ) (θ : SeedWhp c U n_max) (fs : FastState) (dict : State U) :

Complete deterministic invariant of FastState valid for every static seed θ.

def Cslib.DataStructure.Dictionary.SuccinctWhp.ValidWhpState (c U V n_max : ℕ) (θ : SeedWhp c U n_max) (st : WhpDictState) (dict : State U) :

Combined representation invariant for WhpDictState across all n_max.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.validFastState_empty {c U V n_max : ℕ} (hth : whpThreshold c ≤ n_max) (θ : SeedWhp c U n_max) :
ValidFastState c U V n_max θ (emptyFastState n_max) (empty U)
theorem Cslib.DataStructure.Dictionary.SuccinctWhp.whpInitPure_spec (c U V n_max : ℕ) (θ : SeedWhp c U n_max) :
ValidWhpState c U V n_max θ (whpInitPure c n_max) (empty U)

whpInitPure satisfies ValidWhpState for Dictionary.empty U.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidFastState.liveInsCount_le {c U V n_max : ℕ} {θ : SeedWhp c U n_max} {fs : FastState} {dict : State U} (hv : ValidFastState c U V n_max θ fs dict) {b : ℕ} (hb : b < numBucketsWhp n_max) :
theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidFastState.fastFindLoc_spec {c U V n_max : ℕ} {θ : SeedWhp c U n_max} {fs : FastState} {dict : State U} (hv : ValidFastState c U V n_max θ fs dict) (u : Fin U) :
have b := FeistelQuotient.feistelBucket (bWhp n_max) (bktHash c U n_max θ.1) ↑u; have q := FeistelQuotient.keyQuotient (bWhp n_max) ↑u; match fastFindLoc c U n_max θ fs u with | some loc => loc < fs.bktCount b ∧ fs.quotArr (FastState.physSlot n_max fs b loc) = q | none => dict u = none

Exact soundness and completeness of fastFindLoc for every seed θ:

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidFastState.fastQuery_spec {c U V n_max : ℕ} {θ : SeedWhp c U n_max} {fs : FastState} {dict : State U} (hv : ValidFastState c U V n_max θ fs dict) (u : Fin U) :
fastQuery c U n_max θ fs u = dict u

fastQuery returns dict u for every seed θ whenever ValidFastState holds.

Section 5: Mode transitions (fastToCsr_spec, csrToFast_spec, trySelfHeal_spec) #

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidFastState.physSlot_lt_and_inj {c U V n_max : ℕ} {θ : SeedWhp c U n_max} {fs : FastState} {dict : State U} (hv : ValidFastState c U V n_max θ fs dict) :
(∀ b < numBucketsWhp n_max, ∀ loc < fs.bktCount b, FastState.physSlot n_max fs b loc < n_max) ∧ ∀ b₁ < numBucketsWhp n_max, ∀ l₁ < fs.bktCount b₁, ∀ b₂ < numBucketsWhp n_max, ∀ l₂ < fs.bktCount b₂, FastState.physSlot n_max fs b₁ l₁ = FastState.physSlot n_max fs b₂ l₂ → b₁ = b₂ ∧ l₁ = l₂

Physical slot < n_max and injectivity for any ValidFastState.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.ValidFastState.fastToCsr_spec {c U V n_max : ℕ} {θ : SeedWhp c U n_max} {fs : FastState} {dict : State U} (hv : ValidFastState c U V n_max θ fs dict) :
have csr := fastToCsr n_max fs; ValidCsrState U V n_max (bktHash c U n_max θ.1) csr dict ∧ ∀ (p : ℕ), csr.qArr p < 2 ^ quotBitsWhp U n_max ∧ csr.vArr p < max V 1

fastToCsr converts any ValidFastState into a ValidCsrState preserving global (q, v) bounds.

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.trySelfHeal_spec {c U V n_max : ℕ} (hth : whpThreshold c ≤ n_max) {θ : SeedWhp c U n_max} {csr : CsrState} {dict : State U} (hcsr : ValidCsrState U V n_max (bktHash c U n_max θ.1) csr dict) (hqv : ∀ (p : ℕ), csr.qArr p < 2 ^ quotBitsWhp U n_max ∧ csr.vArr p < max V 1) :
have st' := trySelfHeal c U n_max θ csr; ValidWhpState c U V n_max θ st' dict ∧ (GoodSeedOnState c U n_max θ dict → ∃ (fs' : FastState), st' = WhpDictState.fast fs' ∧ fs'.buf 0 = emptyBufTrie ∧ fs'.buf 1 = emptyBufTrie ∧ fs'.curEp = 0 ∧ fs'.epochClock = 0 ∧ fs'.rebStage = 5)

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).

theorem Cslib.DataStructure.Dictionary.SuccinctWhp.csrStepOp_spec {c U V n_max : ℕ} (hnU : n_max ≤ U) (θ₁ : BktSeed c U n_max) {csr : CsrState} {dict : State U} (hcsr : ValidCsrState U V n_max (bktHash c U n_max θ₁) csr dict) (hqv : ∀ (p : ℕ), csr.qArr p < 2 ^ quotBitsWhp U n_max ∧ csr.vArr p < max V 1) {op : Dynamic.Op U} (hvalid : Dynamic.valid V n_max dict op) :
match csrStepOp c U n_max θ₁ csr op with | (csr', res) => ValidCsrState U V n_max (bktHash c U n_max θ₁) csr' (Dynamic.step dict op).1 ∧ res = opResultOpt op (Dynamic.step dict op).2 ∧ ∀ (p : ℕ), csr'.qArr p < 2 ^ quotBitsWhp U n_max ∧ csr'.vArr p < max V 1

csrStepOp preserves ValidCsrState and global (q, v) bounds while refining Dynamic.step.