type Comparator = (a: T, b: T) => number; declare class Heap { private readonly data; private readonly compare; /** * @param compare - Comparator function. Return negative to place `a` above * `b` in the heap (i.e. closer to the top / higher priority). * @param initial - Optional array of items to heapify in O(n) time. * The array is copied; the original is not modified. */ constructor(compare: Comparator, initial?: T[]); /** Number of items currently in the heap. */ get size(): number; /** True when the heap contains no items. */ get isEmpty(): boolean; /** Return the top item without removing it. O(1). */ peek(): T | undefined; /** Add an item. O(log n). */ push(item: T): void; /** Remove and return the top item. O(log n). */ pop(): T | undefined; /** * Push a new item and pop the top in one pass — more efficient than calling * push() then pop() separately because it avoids an extra sift. O(log n). */ pushPop(item: T): T; /** * Pop the top item and push a replacement in one pass — more efficient than * pop() then push() separately. Throws if the heap is empty. O(log n). */ replace(item: T): T; /** * Remove the first item that satisfies the predicate. * Returns the removed item, or undefined if not found. * * Finding the item is O(n). The removal itself is O(log n). */ remove(predicate: (item: T) => boolean): T | undefined; /** * Remove all items that satisfy the predicate. Returns the removed items in * the order they were found (not priority order). * * O(n) to scan + O(k log n) for k removals. */ removeAll(predicate: (item: T) => boolean): T[]; /** Remove all items. */ clear(): void; /** * Add multiple items at once. More efficient than repeated push() calls * when adding many items: uses heapify (O(n)) rather than O(n log n). */ pushAll(items: Iterable): void; /** * Drain all items in priority order. The heap is empty afterward. * Equivalent to calling pop() until empty, but expressed as a generator * so callers can break early without popping everything. O(n log n) total. */ drain(): Generator; /** * Return a sorted array of all items in priority order without mutating * the heap. O(n log n). */ toSortedArray(): T[]; private siftUp; private siftDown; private removeAt; } export { type Comparator, Heap };