Indexed Binary Min-Heap: Exact-Basis Word-RAM Program #
This file defines the structured word-RAM code (Cslib.WordRAM.Code .exact 25) and PQCode
calling convention for the standalone indexed binary min-heap on rBin = 25 registers.
Registers 0..4 (baseReg, nReg, hb, pb, sz) are persistent (input = false); registers
5..24 (frontierReg, tags, arguments, outputs, constants, and sift scratch registers) are
caller-overwritable (input = true). Parent positions are computed via p ← k >>> one
(k >>> 1 = k / 2), so no constant larger than 1 is ever loaded and all operations succeed at
every word width w with Fits w (base + space n) and Fits w K_max (including n = 0, w = 1).
Main definitions #
Cslib.Algorithms.WordRAM.PriorityQueue.BinaryHeap.rBin: register count (25).Cslib.Algorithms.WordRAM.PriorityQueue.BinaryHeap.siftUp,Cslib.Algorithms.WordRAM.PriorityQueue.BinaryHeap.siftDown: heap-order restoration loops.Cslib.Algorithms.WordRAM.PriorityQueue.BinaryHeap.pqCode: packagedPQCode .exact rBin.
References #
Total register count of the standalone binary heap (5 persistent + 20 caller/scratch).
Instances For
Persistent base address base of the key array ([base, base + n)).
Instances For
Persistent handle bound n.
Instances For
Persistent pos array base base + 2 * n + 1.
Instances For
Bump-allocation frontier register.
Instances For
High operation-tag bit (1 iff extractMin).
Instances For
Middle operation-tag bit (1 iff insert or decreaseKey).
Instances For
Low operation-tag bit.
Instances For
Input handle argument v.val.
Instances For
Output status/presence flag (output register).
Instances For
Output handle register (extractMin).
Instances For
Output key register (getKey, extractMin).
Instances For
Scratch constant 0 (also zeroReg for SubroutineCode.zeroFillCode).
Instances For
Scratch constant 1 (also oneReg for SubroutineCode.zeroFillCode).
Instances For
Scratch address / comparison register (also curReg for SubroutineCode.zeroFillCode).
Instances For
Register classification: 0..4 are persistent (false), 5..24 are caller/scratch (true).
Instances For
Bump-allocate space n = 3 * n + 1 words at frontierReg, recording baseReg, hb, and pb.
Instances For
Initialize hb := base + n, pb := base + 2 * n + 1, and sz := 0 assuming
[base, base + space n) is already zero-filled.
Instances For
Swap heap entries at positions k (handle vk) and p (handle vp), updating pos.
Instances For
Set t := 1 iff IndexedMinPQ.RawPrioLT (vA, dA) (vB, dB), else t := 0.
Instances For
Set t := 1 iff IndexedMinPQ.RawPrioLT (vk, dk) (vp, dp), else t := 0.
Instances For
Set t := 1 iff IndexedMinPQ.RawPrioLT (vp, dp) (vk, dk), else t := 0.
Instances For
Repair upward from position k.
Instances For
Choose the lexicographically smaller child of k (l vs l + 1) into (p, vp, dp).
Instances For
Swap k with chosen child (p, vp, dp) if IndexedMinPQ.RawPrioLT (vp, dp) (vk, dk), else
stop siftDown.
Instances For
One iteration of siftDown.
Instances For
Repair downward from position k.
Instances For
Handle isEmpty: outFlag := 1 when sz = 0, outFlag := 0 otherwise.
Instances For
Handle getKey v: sets outFlag := 0 if pos[v] = 0, else outFlag := 1 and
outK := key[v].
Instances For
Handle insert v k: stores key[v] := argK, appends v at sz + 1, and sifts up.
Instances For
Handle decreaseKey v k: updates key[v] := argK, reads k := pos[v], and sifts up.
Instances For
Non-empty branch of extractMin: reads root into (outV, outK), clears pos[outV], moves last
entry to root when sz - 1 > 0, and sifts down.
Instances For
Handle extractMin: sets outFlag := 0 if empty, otherwise runs doExtractNonEmpty.
Instances For
Dispatch a single IndexedMinPQ.Op encoded in (tag2, tag1, tag0, argV, argK).
Instances For
Packaged PQCode .exact rBin for the standalone binary heap.