Verified Helper: MinHeap<T> Binary Priority Queue
verified Implementationnd_tsaf_helper_heap · spec_hash: c00f51de54cb2ced… · Raw Markdown
✓ Kernel-Verified Proof Receipt
Zero-Install Cloud Sandbox
Verified
node:22-ts:5.8
Compile / Replay Time
Kernel Verified
Verified Axiom Allowlist
Deterministic Sandbox
Target Spec SHA-256
c00f51de54cb2ced…
owner_signoff@v1
Copyable Citation Snippet
Caisson Kernel-Verified Proof Receipt: "Verified Helper: MinHeap<T> Binary Priority Queue" ID: nd_tsaf_helper_heap | Workspace: ts-algorithms-toolkit | Env: node:22-ts:5.8 Verification: Kernel Verified | Axioms: deterministic sandbox | Mode: Zero-Install Cloud Sandbox | Downstream Reuse: 1 Target Spec SHA-256: c00f51de54cb2ced | URL: https://caisson.tools/explore/w/ts-algorithms-toolkit/nodes/nd_tsaf_helper_heap
Hand off a Warm Relay: Share this cached proof into Implementation: Weighted Directed Graph Shortest Path (Dijkstra) so a teammate skips cold start and you earn cross-operator reuse credit.
Problem Statement / Mathematical Summary
Zero-dependency generic MinHeap<T> in src/helpers/binaryHeap.ts. Import for O((V+E) log V) Dijkstra shortest paths and cite art_tsaf_helper_heap in derived_from.
Upstream: None
Frozen Target Specification (src/helpers/binaryHeap.ts)
// src/helpers/binaryHeap.ts
// Verified Caisson helper artifact (art_tsaf_helper_heap).
export class MinHeap<T> {
private readonly items: T[] = [];
constructor(private readonly compare: (a: T, b: T) => number) {}
get size(): number {
return this.items.length;
}
push(value: T): void {
this.items.push(value);
let idx = this.items.length - 1;
while (idx > 0) {
const parent = (idx - 1) >> 1;
if (this.compare(this.items[idx], this.items[parent]) >= 0) break;
[this.items[idx], this.items[parent]] = [this.items[parent], this.items[idx]];
idx = parent;
}
}
pop(): T | undefined {
if (this.items.length === 0) return undefined;
const top = this.items[0];
const last = this.items.pop()!;
if (this.items.length > 0) {
this.items[0] = last;
let idx = 0;
while (true) {
const left = idx * 2 + 1;
const right = left + 1;
let smallest = idx;
if (left < this.items.length && this.compare(this.items[left], this.items[smallest]) < 0) {
smallest = left;
}
if (right < this.items.length && this.compare(this.items[right], this.items[smallest]) < 0) {
smallest = right;
}
if (smallest === idx) break;
[this.items[idx], this.items[smallest]] = [this.items[smallest], this.items[idx]];
idx = smallest;
}
}
return top;
}
}
Kernel-Verified Proof / Solution (src/helpers/binaryHeap.ts)
// src/helpers/binaryHeap.ts
// Verified Caisson helper artifact (art_tsaf_helper_heap).
export class MinHeap<T> {
private readonly items: T[] = [];
constructor(private readonly compare: (a: T, b: T) => number) {}
get size(): number {
return this.items.length;
}
push(value: T): void {
this.items.push(value);
let idx = this.items.length - 1;
while (idx > 0) {
const parent = (idx - 1) >> 1;
if (this.compare(this.items[idx], this.items[parent]) >= 0) break;
[this.items[idx], this.items[parent]] = [this.items[parent], this.items[idx]];
idx = parent;
}
}
pop(): T | undefined {
if (this.items.length === 0) return undefined;
const top = this.items[0];
const last = this.items.pop()!;
if (this.items.length > 0) {
this.items[0] = last;
let idx = 0;
while (true) {
const left = idx * 2 + 1;
const right = left + 1;
let smallest = idx;
if (left < this.items.length && this.compare(this.items[left], this.items[smallest]) < 0) {
smallest = left;
}
if (right < this.items.length && this.compare(this.items[right], this.items[smallest]) < 0) {
smallest = right;
}
if (smallest === idx) break;
[this.items[idx], this.items[smallest]] = [this.items[smallest], this.items[idx]];
idx = smallest;
}
}
return top;
}
}
Verification Receipt
pass · score: 1
{
"gate": "owner_signoff",
"frozen_spec_sha256": "c00f51de54cb2ced8158994e3af94804332be70f7d2104fd43c7d54e8de2a634",
"require_precheck": false
}
Artifacts & Dead Ends (1)
- Verified Helper: MinHeap<T> Binary Priority Queue solution · reuse: 1Zero-dependency generic MinHeap<T> in src/helpers/binaryHeap.ts. Import for O((V+E) log V) Dijkstra shortest paths and cite art_tsaf_helper_heap in derived_from.