Indexed binary min-heap: the order lemmas of sift-up and sift-down #
These are the machine-free steps of sift-up and sift-down on the indexed binary heap of
Cslib.DataStructure.PriorityQueue.BinaryHeap.Model: swapping two heap positions keeps the
heap shape (HeapShape.swap), and a swap with the parent or with the child of highest priority
moves a single order defect one level (UpOrdered.swap, DownOrdered.swap) until it disappears
(UpOrdered.ordered, DownOrdered.ordered).
These are the machine-free lemmas extracted from Renfei Zhou's original native heap proof.
The memory programs and their native realizations share them without importing a separate
execution proof. They extend the namespace of BinaryHeap.Model, whose definitions they use.
Main definitions #
Cslib.DataStructure.PriorityQueue.BinaryHeap.swapMem: memory after swapping two heap positions.Cslib.DataStructure.PriorityQueue.BinaryHeap.minChild: the child of highest priority.
Main results #
Cslib.DataStructure.PriorityQueue.BinaryHeap.HeapShape.swap: a swap keeps the shape.Cslib.DataStructure.PriorityQueue.BinaryHeap.UpOrdered.swap,Cslib.DataStructure.PriorityQueue.BinaryHeap.UpOrdered.ordered,Cslib.DataStructure.PriorityQueue.BinaryHeap.Ordered.upOrdered_one: sift-up.Cslib.DataStructure.PriorityQueue.BinaryHeap.DownOrdered.swap,Cslib.DataStructure.PriorityQueue.BinaryHeap.DownOrdered.ordered,Cslib.DataStructure.PriorityQueue.BinaryHeap.minChild_spec: sift-down.
References #
One step of sift-up. Swapping an entry a with its parent when it has higher priority
moves the upward defect to the parent.
A heap with one downward defect at a is ordered once a is ordered with its children.
One step of sift-down. Swapping an entry a with its child c of highest priority,
when c has higher priority than a, moves the downward defect to c.
Swapping two heap positions keeps the heap shape, exchanges the two entries, leaves the other entries, the presence of every handle, and every cell outside the heap and position arrays unchanged.