Fast Insertion Slot Allocation & Write Primitives #
Low-level mutating primitives for fresh fast insertions: backyard slot pop/binding, (q, v) slot
writes, and collision vs. direct insertion commit steps.
Main definitions #
Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.fastInsertAllocGenProgCslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.insWriteQVAtGenProgCslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.insFinishCollisionGenProgCslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.insFinishDirectGenProg
Main results #
Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.fastInsertAllocGenProg_fastStepCslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.insWriteQVAtGenProg_fastStepCslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.insFinishCollisionGenProg_fastStepCslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.insFinishDirectGenProg_fastStep
@[irreducible]
Allocate backyard slot at (b, X) when capFrontWhp ≤ X (d = (((cp, base), b), X)).
theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.realizes_fastInsertAllocGen :
WordRAM.Realization.Realizes WordRAM.Basis.exact fastInsertAllocGenProg WordRAM.Realization.WordEncoding.encode
WordRAM.Realization.WordEncoding.encode
(fun (w : ℕ) (x : ((WhpCoreParams × ℕ) × ℕ) × ℕ) (s : Memory.State) =>
match x with
| (((cp, base), b), X) =>
∃ (c : ℕ) (U : ℕ) (V : ℕ) (w₀ : ℕ) (n_max : ℕ) (fs : SuccinctWhp.FastState),
WhpLargeEnv c U V w₀ n_max w base ∧ cp = mkWhpCoreParams c U V w₀ n_max ∧ FastMemRep base c U V w₀ n_max fs s.mem ∧ b < SuccinctWhp.numBucketsWhp n_max ∧ X < SuccinctWhp.totalLocalCoordsWhp n_max ∧ (SuccinctWhp.capFrontWhp n_max ≤ X →
0 < fs.poolFreeTop ∧ fs.poolFreeTop ≤ SuccinctWhp.poolSizeWhp n_max ∧ fs.poolFreeStack (fs.poolFreeTop - 1) < SuccinctWhp.poolSizeWhp n_max))
fun (x : ((WhpCoreParams × ℕ) × ℕ) × ℕ) (x_1 : Memory.State) => 0
theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.fastInsertAllocGenProg_fastStep {c U V w n_max base b X : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs : SuccinctWhp.FastState} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hb : b < SuccinctWhp.numBucketsWhp n_max) (hX_tl : X < SuccinctWhp.totalLocalCoordsWhp n_max) (hcf_fn :
SuccinctWhp.capFrontWhp n_max ≤ X →
0 < fs.poolFreeTop ∧ fs.poolFreeTop ≤ SuccinctWhp.poolSizeWhp n_max ∧ fs.poolFreeStack (fs.poolFreeTop - 1) < SuccinctWhp.poolSizeWhp n_max) (hseed : SeedWhpMemRep base c U w n_max θ s.mem) (hrep : FastMemRep base c U V w n_max fs s.mem) :
have prog := fastInsertAllocGenProg (((mkWhpCoreParams c U V w n_max, base), b), X);
have s' := (Memory.spec 0).clientState s prog;
WordRAM.Realization.memoryCost prog s ≤ 12 ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ FastStateStep base c U V w n_max θ (SuccinctWhp.fastInsertAlloc n_max b X fs) s s'
@[irreducible]
Write (q_val, v_val) at physSlot b X (d = ((((cp, base), b), X), (q_val, v_val))).
theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.realizes_insWriteQVAtGen :
WordRAM.Realization.Realizes WordRAM.Basis.exact insWriteQVAtGenProg WordRAM.Realization.WordEncoding.encode
WordRAM.Realization.WordEncoding.encode
(fun (w : ℕ) (x : (((WhpCoreParams × ℕ) × ℕ) × ℕ) × ℕ × ℕ) (s : Memory.State) =>
match x with
| ((((cp, base), b), X), q_val, snd) =>
∃ (c : ℕ) (U : ℕ) (V : ℕ) (w₀ : ℕ) (n_max : ℕ) (θ : SuccinctWhp.SeedWhp c U n_max) (fs : SuccinctWhp.FastState),
WhpLargeEnv c U V w₀ n_max w base ∧ cp = mkWhpCoreParams c U V w₀ n_max ∧ SeedWhpMemRep base c U w₀ n_max θ s.mem ∧ FastMemRep base c U V w₀ n_max fs s.mem ∧ b < SuccinctWhp.numBucketsWhp n_max ∧ X < SuccinctWhp.totalLocalCoordsWhp n_max ∧ (SuccinctWhp.capFrontWhp n_max ≤ X →
fs.backPtr b (X - SuccinctWhp.capFrontWhp n_max) < SuccinctWhp.poolSizeWhp n_max) ∧ q_val < 2 ^ SuccinctWhp.quotBitsWhp U n_max)
fun (x : (((WhpCoreParams × ℕ) × ℕ) × ℕ) × ℕ × ℕ) (x_1 : Memory.State) => 0
theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.insWriteQVAtGenProg_fastStep {c U V w n_max base b X q_val v_val : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs : SuccinctWhp.FastState} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hb : b < SuccinctWhp.numBucketsWhp n_max) (hX_tl : X < SuccinctWhp.totalLocalCoordsWhp n_max) (hbp :
SuccinctWhp.capFrontWhp n_max ≤ X → fs.backPtr b (X - SuccinctWhp.capFrontWhp n_max) < SuccinctWhp.poolSizeWhp n_max) (hq_lt : q_val < 2 ^ SuccinctWhp.quotBitsWhp U n_max) (hv_lt : v_val < 2 ^ FeistelQuotient.valBits V) (hseed : SeedWhpMemRep base c U w n_max θ s.mem) (hrep : FastMemRep base c U V w n_max fs s.mem) :
have prog := insWriteQVAtGenProg ((((mkWhpCoreParams c U V w n_max, base), b), X), q_val, v_val);
have s' := (Memory.spec 0).clientState s prog;
have p_new := SuccinctWhp.FastState.physSlot n_max fs b X;
WordRAM.Realization.memoryCost prog s ≤ 10 ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ FastStateStep base c U V w n_max θ
{ quotArr := Function.update fs.quotArr p_new q_val, valArr := Function.update fs.valArr p_new v_val,
locState := fs.locState, bktCount := fs.bktCount, bktSalt := fs.bktSalt, liveRole := fs.liveRole,
liveInsCount := fs.liveInsCount, overmarsRole := fs.overmarsRole, overmarsActive := fs.overmarsActive,
overmarsCursor := fs.overmarsCursor, overmarsInsCount := fs.overmarsInsCount, rebDoneFlag := fs.rebDoneFlag,
rebQueued := fs.rebQueued, backPtr := fs.backPtr, poolFreeTop := fs.poolFreeTop,
poolFreeStack := fs.poolFreeStack, poolOwner := fs.poolOwner, slices := fs.slices, buf := fs.buf,
curEp := fs.curEp, epochClock := fs.epochClock, rebStage := fs.rebStage, stageCursor := fs.stageCursor,
dirtyCount := fs.dirtyCount, dirtyBuckets := fs.dirtyBuckets, dirtyIdx := fs.dirtyIdx,
rebCandSalt := fs.rebCandSalt, rebScanCursor := fs.rebScanCursor, rebInsCount := fs.rebInsCount,
rebCollision := fs.rebCollision }
s s'
@[irreducible]
Finish collision insertion (hasFpCollision = true): write bktCount, locState := 2 + curEp,
and insert (b, X) into buf curEp (d = ((((cp, base), b), X), rKey)).
theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.realizes_insFinishCollisionGen :
WordRAM.Realization.Realizes WordRAM.Basis.exact insFinishCollisionGenProg WordRAM.Realization.WordEncoding.encode
WordRAM.Realization.WordEncoding.encode
(fun (w : ℕ) (x : (((WhpCoreParams × ℕ) × ℕ) × ℕ) × ℕ) (s : Memory.State) =>
match x with
| ((((cp, base), b), X), snd) =>
∃ (c : ℕ) (U : ℕ) (V : ℕ) (w₀ : ℕ) (n_max : ℕ) (θ : SuccinctWhp.SeedWhp c U n_max) (fs : SuccinctWhp.FastState)
(curMap : ℕ → Option (ℕ × ℕ)),
WhpLargeEnv c U V w₀ n_max w base ∧ cp = mkWhpCoreParams c U V w₀ n_max ∧ SeedWhpMemRep base c U w₀ n_max θ s.mem ∧ FastMemRep base c U V w₀ n_max fs s.mem ∧ (fs.curEp = 0 ∨ fs.curEp = 1) ∧ b < SuccinctWhp.numBucketsWhp n_max ∧ X < SuccinctWhp.totalLocalCoordsWhp n_max ∧ (fs.buf fs.curEp).nodeAlloc + SuccinctWhp.cTabWhp c ≤ SuccinctWhp.maxTrieNodesWhp c n_max ∧ (fs.buf fs.curEp).itemAlloc < SuccinctWhp.qEpochWhp n_max ∧ SuccinctWhp.ValidBufTrie (SuccinctWhp.cTabWhp c) (SuccinctWhp.bCharWhp n_max)
(fs.buf fs.curEp) curMap)
fun (x : (((WhpCoreParams × ℕ) × ℕ) × ℕ) × ℕ) (x_1 : Memory.State) => 0
@[irreducible]
Finish direct insertion (hasFpCollision = false): write bktCount, locState := 1, insert
(fp, X) into slices lIdx, and increment liveInsCount b.
theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.realizes_insFinishDirectGen :
WordRAM.Realization.Realizes WordRAM.Basis.exact insFinishDirectGenProg WordRAM.Realization.WordEncoding.encode
WordRAM.Realization.WordEncoding.encode
(fun (w : ℕ) (x : (((WhpCoreParams × ℕ) × ℕ) × ℕ) × ℕ × ℕ) (s : Memory.State) =>
match x with
| ((((cp, base), b), X), fp, lIdx) =>
∃ (c : ℕ) (U : ℕ) (V : ℕ) (w₀ : ℕ) (n_max : ℕ) (θ : SuccinctWhp.SeedWhp c U n_max) (fs : SuccinctWhp.FastState)
(lm : ℕ → Option ℕ),
WhpLargeEnv c U V w₀ n_max w base ∧ cp = mkWhpCoreParams c U V w₀ n_max ∧ SeedWhpMemRep base c U w₀ n_max θ s.mem ∧ FastMemRep base c U V w₀ n_max fs s.mem ∧ b < SuccinctWhp.numBucketsWhp n_max ∧ X < SuccinctWhp.totalLocalCoordsWhp n_max ∧ lIdx = fs.liveSliceIdx b ∧ lIdx < 3 * SuccinctWhp.numBucketsWhp n_max ∧ fp < 2 ^ SuccinctWhp.fpBitsWhp n_max ∧ fs.liveInsCount b ≤ 8 * FeistelQuotient.slabScale n_max ^ 12 ∧ SuccinctWhp.ValidWhpSlice n_max (fs.liveInsCount b) (fs.slices lIdx) lm)
fun (x : (((WhpCoreParams × ℕ) × ℕ) × ℕ) × ℕ × ℕ) (x_1 : Memory.State) => 0
theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.insFinishCollisionGenProg_fastStep {c U V w n_max base b X rKey : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs : SuccinctWhp.FastState} {curMap : ℕ → Option (ℕ × ℕ)} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hce : fs.curEp = 0 ∨ fs.curEp = 1) (hb : b < SuccinctWhp.numBucketsWhp n_max) (hX_tl : X < SuccinctWhp.totalLocalCoordsWhp n_max) (hna_cap : (fs.buf fs.curEp).nodeAlloc + SuccinctWhp.cTabWhp c ≤ SuccinctWhp.maxTrieNodesWhp c n_max) (hia_cap : (fs.buf fs.curEp).itemAlloc < SuccinctWhp.qEpochWhp n_max) (hv_cur : SuccinctWhp.ValidBufTrie (SuccinctWhp.cTabWhp c) (SuccinctWhp.bCharWhp n_max) (fs.buf fs.curEp) curMap) (hseed : SeedWhpMemRep base c U w n_max θ s.mem) (hrep : FastMemRep base c U V w n_max fs s.mem) :
have prog := insFinishCollisionGenProg ((((mkWhpCoreParams c U V w n_max, base), b), X), rKey);
have s' := (Memory.spec 0).clientState s prog;
have ep := fs.curEp;
have tr' := SuccinctWhp.bufInsert (SuccinctWhp.cTabWhp c) (SuccinctWhp.bCharWhp n_max) (fs.buf ep) rKey b X;
WordRAM.Realization.memoryCost prog s ≤ 20 * SuccinctWhp.cTabWhp c + 33 ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ FastStateStep base c U V w n_max θ
{ quotArr := fs.quotArr, valArr := fs.valArr,
locState := Function.update fs.locState b (Function.update (fs.locState b) X (2 + ep)),
bktCount := Function.update fs.bktCount b (X + 1), bktSalt := fs.bktSalt, liveRole := fs.liveRole,
liveInsCount := fs.liveInsCount, overmarsRole := fs.overmarsRole, overmarsActive := fs.overmarsActive,
overmarsCursor := fs.overmarsCursor, overmarsInsCount := fs.overmarsInsCount, rebDoneFlag := fs.rebDoneFlag,
rebQueued := fs.rebQueued, backPtr := fs.backPtr, poolFreeTop := fs.poolFreeTop,
poolFreeStack := fs.poolFreeStack, poolOwner := fs.poolOwner, slices := fs.slices,
buf := Function.update fs.buf ep tr', curEp := fs.curEp, epochClock := fs.epochClock, rebStage := fs.rebStage,
stageCursor := fs.stageCursor, dirtyCount := fs.dirtyCount, dirtyBuckets := fs.dirtyBuckets,
dirtyIdx := fs.dirtyIdx, rebCandSalt := fs.rebCandSalt, rebScanCursor := fs.rebScanCursor,
rebInsCount := fs.rebInsCount, rebCollision := fs.rebCollision }
s s'
theorem Cslib.DataStructure.Dictionary.WordRAM.SuccinctWhp.insFinishDirectGenProg_fastStep {c U V w n_max base b X fp lIdx : ℕ} {θ : SuccinctWhp.SeedWhp c U n_max} {fs : SuccinctWhp.FastState} {lm : ℕ → Option ℕ} {s : Memory.State} (henv : WhpLargeEnv c U V w n_max w base) (hb : b < SuccinctWhp.numBucketsWhp n_max) (hX_tl : X < SuccinctWhp.totalLocalCoordsWhp n_max) (hlIdx_eq : lIdx = fs.liveSliceIdx b) (hlIdx : lIdx < 3 * SuccinctWhp.numBucketsWhp n_max) (hfp_lt : fp < 2 ^ SuccinctWhp.fpBitsWhp n_max) (hlic : fs.liveInsCount b ≤ 8 * FeistelQuotient.slabScale n_max ^ 12) (hv_l : SuccinctWhp.ValidWhpSlice n_max (fs.liveInsCount b) (fs.slices lIdx) lm) (hseed : SeedWhpMemRep base c U w n_max θ s.mem) (hrep : FastMemRep base c U V w n_max fs s.mem) :
have prog := insFinishDirectGenProg ((((mkWhpCoreParams c U V w n_max, base), b), X), fp, lIdx);
have s' := (Memory.spec 0).clientState s prog;
have sl' :=
SuccinctWhp.btreeInsert (SuccinctWhp.fpBitsWhp n_max) (SuccinctWhp.valLaneBitsWhp n_max) (SuccinctWhp.tMinWhp n_max)
(fs.slices lIdx) fp X;
WordRAM.Realization.memoryCost prog s ≤ 2440 ∧ Succinct.ValidProg w (base + SuccinctWhp.largeSpaceWhp c U V w n_max) s prog ∧ FastStateStep base c U V w n_max θ
{ quotArr := fs.quotArr, valArr := fs.valArr,
locState := Function.update fs.locState b (Function.update (fs.locState b) X 1),
bktCount := Function.update fs.bktCount b (X + 1), bktSalt := fs.bktSalt, liveRole := fs.liveRole,
liveInsCount := Function.update fs.liveInsCount b (fs.liveInsCount b + 1), overmarsRole := fs.overmarsRole,
overmarsActive := fs.overmarsActive, overmarsCursor := fs.overmarsCursor,
overmarsInsCount := fs.overmarsInsCount, rebDoneFlag := fs.rebDoneFlag, rebQueued := fs.rebQueued,
backPtr := fs.backPtr, poolFreeTop := fs.poolFreeTop, poolFreeStack := fs.poolFreeStack,
poolOwner := fs.poolOwner, slices := Function.update fs.slices lIdx sl', buf := fs.buf, curEp := fs.curEp,
epochClock := fs.epochClock, rebStage := fs.rebStage, stageCursor := fs.stageCursor,
dirtyCount := fs.dirtyCount, dirtyBuckets := fs.dirtyBuckets, dirtyIdx := fs.dirtyIdx,
rebCandSalt := fs.rebCandSalt, rebScanCursor := fs.rebScanCursor, rebInsCount := fs.rebInsCount,
rebCollision := fs.rebCollision }
s s'