Build the max-heap
# grade this stage (from your course directory)
npx theinference test --stage max-heap --watchNow the max-heap for the result set W. It is a min-heap with the comparison reversed: the root is the entry with the largest distance — the worst keeper, the one you evict when a closer result arrives and W is full.
A max-heap is a min-heap with the order flipped. The clean move is to parameterize a single heap by a less comparator and instantiate both MinHeap and MaxHeap from it — that is exactly what you will wire into C and W inside SEARCH-LAYER.
What to build
Implement MaxHeap
Implement MaxHeap in src/heap.ts, then expose runMaxHeap(ops). Same op-log replay as the min-heap, but pops return the furthest entry first.
export function runMaxHeap(ops: HeapOp[]): number[] {
// replay ops on a MaxHeap; return the id of each popped (furthest-first) Entry
}
Even in the max-heap, on equal distance the smaller id pops first. Keeping the tie-break consistent across both heaps is what makes the whole search reproducible — a tie that flips here can flip a result id three chapters later.
Adapter mode: the popped-id sequence is compared exactly to the reference for the same fixed op log used by the min-heap.