Documentation

CslibFrontier.DataStructure.PriorityQueue.WordRAM.SoftHeap.Collect

Corrupted-Item Collection Specification for Word-RAM Soft Heaps #

Proves shCollectCorrupted_spec: scanning node indices (nc₀, h.nodeCount] appends all surviving corrupted items (origKey < ckey) into outBase[outCount..newOut), preserves SHInv and memory framing outside the written output slice, and satisfies memoryCost (shCollectCorrupted ...) s ≤ 8 * (h.itemCount - ic₀).

Main results #

theorem Cslib.DataStructure.PriorityQueue.WordRAM.SoftHeap.shCollectCorrupted_spec {w ic₀ nc₀ maxItems maxNodes outBase outCount outCap fuel : ℕ} {h : SHHandle} {roots : List SHTree} {created : ℕ → ℕ} {s : Memory.State} (hinv : SHInv w ic₀ nc₀ maxItems maxNodes h roots created s) (hfuel : h.itemCount - ic₀ ≤ fuel) (hout_le : outCount + (List.filter (fun (p : SHItem × ℕ) => decide (p.1.origKey < p.2)) (forestEntries roots)).length ≤ outCap) (hout_lt : outBase + outCap ≤ s.frontier) (hout_fit : WordRAM.Fits w (outCap + 1)) (hout_disj : ∀ (a : ℕ), outBase + outCount ≤ a → a < outBase + outCap → ¬InSHPool ic₀ nc₀ maxItems maxNodes h a) :
(Memory.spec w).ValidHistory s ((Memory.spec w).clientHistory s (shCollectCorrupted (h, nc₀, outBase, outCount, fuel))) ∧ shCollectCorruptedSafe w (h, nc₀, outBase, outCount, fuel) s ∧ have newOut := (Memory.spec 0).clientResult s (shCollectCorrupted (h, nc₀, outBase, outCount, fuel)); have s' := (Memory.spec 0).clientState s (shCollectCorrupted (h, nc₀, outBase, outCount, fuel)); newOut = outCount + (List.filter (fun (p : SHItem × ℕ) => decide (p.1.origKey < p.2)) (forestEntries roots)).length ∧ s'.frontier = s.frontier ∧ (∀ (a : ℕ), s'.mem a ≠ s.mem a → outBase + outCount ≤ a ∧ a < outBase + newOut) ∧ SHInv w ic₀ nc₀ maxItems maxNodes h roots created s' ∧ (List.map (fun (i : ℕ) => s'.mem (outBase + outCount + i)) (List.range (newOut - outCount))).Perm (List.map (fun (p : SHItem × ℕ) => p.1.val) (List.filter (fun (p : SHItem × ℕ) => decide (p.1.origKey < p.2)) (forestEntries roots))) ∧ WordRAM.Realization.memoryCost (shCollectCorrupted (h, nc₀, outBase, outCount, fuel)) s ≤ 8 * (h.itemCount - ic₀)

Full specification of shCollectCorrupted: scans all allocated nodes (nc₀, h.nodeCount], appends every surviving corrupted item's val (origKey < ckey) to outBase[outCount..], preserves SHInv and framing outside outBase[outCount..newOut), and spends memoryCost ≤ 8 * (h.itemCount - ic₀) (uniformly realized via realizes_shCollectCorrupted).