Build the min-heap
# grade this stage (from your course directory)
npx theinference test --stage min-heap --watchBuild the min-heap that will hold the candidate queue C. A binary heap stored in an array: push adds and sifts up, pop removes the root and sifts down. The root is always the entry with the smallest distance.
What to build
Implement MinHeap
Implement MinHeap in src/heap.ts — push(e), pop() (smallest distance), peek(), size() — over Entry { dist, id }. The harness drives it through runMinHeap(ops), which replays a push/pop op log and returns the sequence of popped ids.
type HeapOp = { op: "push"; dist: number; id: number } | { op: "pop" };
export function runMinHeap(ops: HeapOp[]): number[] {
// replay ops on a MinHeap; return the id of each popped Entry, in order
}
When two entries have equal distance, treat the one with the smaller id as having higher priority (it pops first). This makes two correct heaps pop the same order — which the downstream search and select steps depend on for determinism.
Adapter mode: the popped-id sequence is compared exactly (atol 0) to the reference for a fixed op log. A wrong sift direction or a missing tie-break will reorder the pops and fail.