Bounded-Depth Character Trie Buffer (BufTrie) for Deamortized Salt Collisions #
This module formalizes the pure model and exact invariants of the constant-depth character trie
(BufTrie) used for the growing and shrinking epoch buffers (BufCur and BufOld) in the
with-high-probability succinct dynamic dictionary (Bender, Farach-Colton, J. Kuszmaul, and
W. Kuszmaul, SOSA 2024, Section 2.2 Lemma 2.2 and Section 5, pp. 363–373; author copy
pp. 3 and 6).
Each Stage-1 reduced key rKey < 2 ^ (cTab * bChar) is decomposed into cTab digits in base
2 ^ bChar (Cslib.DataStructure.laneGet, eq_of_forall_laneGet_eq_of_lt). Augmenting SOSA
2024's k-trie for deterministic per-step background draining and cleanup without scanning all
2 ^ bChar child slots, a BufTrie stores:
- A rooted
2 ^ bChar-ary trie (root at node0, allocated non-root nodes1 .. nodeAlloc - 1) recording(nodeParent u, nodeChar u)for each1 ≤ u < nodeAllocso all dirty child entries can be re-zeroed incrementally inO(1)logical table updates per clear pop (bufClearOne,bufClearSteps) without scanning2 ^ bCharchildren. - A sequential append log
0 .. itemAlloc - 1(itemLeaf,itemBucket,itemLoc) paired with per-leaf slot indexnodeLeafItem(id + 1, or0if never allocated in this epoch) and flagnodeActive(0if deleted/inactive, non-zero if active), so itemid < itemAllocis active iffnodeLeafItem (itemLeaf id) = id + 1 ∧ nodeActive (itemLeaf id) ≠ 0. Deletion clearsnodeActive leaf := 0while preservingnodeLeafItem leaf(so same-epoch re-insertion reuses slotidwith zero allocations), and the background drainer probes0 .. itemAlloc - 1viabufCheckSlotinO(1)logical table reads per slot without doubly-linked list pointers.
Cost convention: All O(1) and O(cTab) operation descriptions in this module count logical
table accesses/updates or clear pops (with cTab fixed). The definitions use pure Nat arithmetic
and functional ℕ → ℕ tables; this module does not certify Lean runtime or Word-RAM
instruction/memory cost.
Main definitions #
Cslib.DataStructure.Dictionary.SuccinctWhp.BufTrie,emptyBufTrie: pure buffer-trie state.Cslib.DataStructure.Dictionary.SuccinctWhp.bufLookup,bufInsert,bufDelete,bufCheckSlot,bufClearOne,bufClearSteps: pure buffer operations makingO(cTab)logical table accesses/updates for trie walks andO(1)logical table accesses/updates per slot probe or clear pop (for fixedcTab, over pureNatarithmetic and functional tables; Lean runtime and Word-RAM instruction/memory costs are not certified here).Cslib.DataStructure.Dictionary.SuccinctWhp.ValidBufTrie: structural, map-refinement, active-slot, and parent-log invariant forBufTrie.
Main results #
Cslib.DataStructure.Dictionary.SuccinctWhp.validBufTrie_empty,ValidBufTrie.lookup_eq,ValidBufTrie.delete_spec,ValidBufTrie.insert_spec,ValidBufTrie.insert_nodeAlloc_le,ValidBufTrie.checkSlot_some,ValidBufTrie.exists_checkSlot_of_map_some,ValidBufTrie.toClearable,ClearableBufTrie.clearOne_step,ClearableBufTrie.clearSteps_spec: exact map, slot-allocation, active-slot scan, and cleanup specifications.
References #
Pure state of a bounded-depth character trie buffer with append-only item log and parent-edge
log for incremental re-zeroing in O(1) logical table updates per clear pop.
- nodeAlloc : ℕ
Number of allocated trie nodes (
1initially; node0is the root). - itemAlloc : ℕ
Number of allocated item log slots (
0 .. itemAlloc - 1). Child pointer table:
0denotes absent,u ≥ 1denotes child nodeu.Parent node of allocated non-root trie node
u ≥ 1.Character edge from
nodeParent utou.Epoch-allocated item slot
+ 1at leaf nodeu(0if never allocated in this epoch; retained across deletions whilenodeActiverecords whether the slot is currently active).Active flag (
0if deleted/inactive, non-zero if currently active) at leaf nodeu.Leaf trie node associated with item log slot
id.Stored bucket index
bfor item log slotid.Stored local coordinate
locfor item log slotid.
Insert or overwrite rKey ↦ (b, loc) in tr:
Delete rKey from tr in O(cTab) logical table accesses and at most one flag update
(clearing nodeActive leaf := 0 while preserving its epoch slot nodeLeafItem leaf so
re-insertions of rKey allocate zero new slots; pure functional model, not certified Lean or
Word-RAM execution cost).
Scan probe at item slot id < tr.itemAlloc using O(1) logical table reads (pure functional
model, not certified Lean or Word-RAM execution cost): returns some (b, loc) iff item id is
still active (nodeLeafItem (itemLeaf id) = id + 1 ∧ nodeActive (itemLeaf id) ≠ 0).
One elementary cleanup pop using O(1) logical table reads/updates (pure functional model, not
certified Lean or Word-RAM execution cost): zeroes itemAlloc := 0 on every step, pops one
allocated non-root node u = nodeAlloc - 1 and re-zeroes trieChild (nodeParent u) (nodeChar u)
and nodeLeafItem u when 1 < nodeAlloc, and sets nodeAlloc := 1 and nodeLeafItem 0 := 0 when
nodeAlloc ≤ 1.
Execute k elementary bufClearOne pops.
Section 2: Exact structural and map invariant (ValidBufTrie) #
emptyBufTrie satisfies ValidBufTrie for the empty map.
Lookup on a ValidBufTrie agrees with mapFn on < 2 ^ (cTab * bChar).
Allocation and index-range projections of ValidBufTrie for Word-RAM packed-array safety.
Exact specification of bufDelete: preserves ValidBufTrie for
Function.update mapFn rKey none, leaves nodeAlloc, itemAlloc, and bufEverPresent unchanged,
and never activates an inactive item slot.
Exact specification of bufInsert:
- Preserves
ValidBufTrieforFunction.update mapFn rKey (some (b, loc)); - Allocates at most
cTabtrie nodes, incrementsitemAllocby exactly1whenbufEverPresent cTab bChar tr rKey = false, and leavesitemAllocunchanged whenbufEverPresent cTab bChar tr rKey = true; - Sets
bufEverPresentatrKeytotrueand preservesbufEverPresenton all other keys< 2 ^ (cTab * bChar); - Whenever
bufEverPresent cTab bChar tr rKey = true(including re-insertion of a previously deleted key in the same epoch!), leavesnodeAllocanditemAlloccompletely unchanged; - When
mapFn rKey ≠ none(updating an active item's(b, loc)in place), also leaves inactive scan slots (bufCheckSlot _ id = none) unchanged.
Forward scan specification: if bufCheckSlot tr id = some (b, loc), then id < tr.itemAlloc
and some active key k < 2 ^ (cTab * bChar) maps to (b, loc) in mapFn (with leaf
tr.itemLeaf id).
Converse scan specification: every active key mapFn k = some (b, loc) has an active scan slot
id < tr.itemAlloc with bufCheckSlot tr id = some (b, loc). In particular, once
∀ id < tr.itemAlloc, bufCheckSlot tr id = none, mapFn is identically none.
Section 3: Incremental single-pop cleanup (ClearableBufTrie, clearSteps_spec) #
Structural parent-log invariant maintained across intermediate bufClearOne steps while
re-zeroing BufOld in the second half of an epoch.
Every ValidBufTrie satisfies ClearableBufTrie.
Allocation and parent-index projections of ClearableBufTrie for Word-RAM packed-array
safety.
One step of bufClearOne preserves ClearableBufTrie and decrements nodeAlloc toward 1.
Executing k ≥ tr.nodeAlloc elementary bufClearOne steps on any ClearableBufTrie produces a
clean empty ValidBufTrie (mapFn = fun _ => none, nodeAlloc = 1, itemAlloc = 0).
bufInsert preserves the linear bound nodeAlloc ≤ 1 + cTab * itemAlloc across all
insertions, overwrites, and reactivations.