Indexed Binary Min-Heap: Memory Model and Invariant #
This file defines the flat memory layout and structural/ordering invariants of the standalone
word-RAM indexed binary min-heap on N handles 0, …, N - 1 placed at base address base
with footprint space N = 3 * N + 1:
mem (base + v)(v < N): current key of handlev(arbitrary word in0 .. K_max, including0).mem (base + N + i)(1 ≤ i ≤ sz): handle stored at 1-based heap positioni(base + Nis unused).mem (base + 2 * N + 1 + v)(v < N): 1-based heap position of handlev, or0whenvis absent from the priority queue.
Heap entries are ordered by Cslib.Algorithms.Lean.IndexedMinPQ.PrioLE on (handle, key),
breaking equal-key ties toward smaller handle indices so extractMin deterministically implements
Cslib.Algorithms.Lean.IndexedMinPQ.findMin.
Main definitions #
Cslib.Algorithms.WordRAM.PriorityQueue.BinaryHeap.space: footprint size3 * N + 1.Cslib.Algorithms.WordRAM.PriorityQueue.BinaryHeap.stateOfMem: abstractIndexedMinPQ.State Nrepresented in memory.Cslib.Algorithms.WordRAM.PriorityQueue.BinaryHeap.HeapShape,Cslib.Algorithms.WordRAM.PriorityQueue.BinaryHeap.HeapInv: structural and lexicographic heap invariants.Cslib.Algorithms.WordRAM.PriorityQueue.BinaryHeap.UpOrdered,Cslib.Algorithms.WordRAM.PriorityQueue.BinaryHeap.DownOrdered: single-defect invariants duringsiftUpandsiftDown.
References #
Memory footprint size (3 * N + 1 words) of an indexed binary heap over N handles.
Instances For
Abstract IndexedMinPQ.State N decoded from the key and pos arrays at base.
Instances For
Structural binary-heap invariant: positions 1, …, sz store handles < N, and the pos
array at base + 2 * N + 1 is the partial inverse of heap at base + N.
Heap size never exceeds
N.Every occupied heap slot holds a valid handle
< N.pos[heap[i]] = ifor1 ≤ i ≤ sz.Every handle's position is at most
sz.- vertex_pos (v : ℕ) : v < N → mem (base + 2 * N + 1 + v) ≠ 0 → mem (base + N + mem (base + 2 * N + 1 + v)) = v
Every handle with nonzero position
psits atheap[p].
Instances For
Full binary-heap invariant: structural bijection plus lexicographic heap order.
Lexicographic min-heap order on
(handle, key).
Instances For
HeapInv depends only on memory cells inside (Block.mk base (space N)).footprint.
When sz = 0, the represented IndexedMinPQ.State N is empty N.
Size S = 0 iff the represented dom is empty.
Root optimality: the root at position 1 has lexicographically minimum (handle, key)
among all handles present in the heap, so IndexedMinPQ.findMin equals the root entry.
Insertion: storing key c for an absent handle v < N and appending v at S + 1
produces HeapShape and UpOrdered at S + 1.
Decrease-key: lowering the key of a present handle v < N from mem (base + v) to c
produces HeapShape and UpOrdered at pos[v].
Root removal (2 ≤ S): clearing the root's position and moving the last entry to 1
produces HeapShape of size S - 1 and DownOrdered at 1.
Singleton root removal: clearing the root's position on a 1-element heap leaves the empty heap invariant.