export * from "./_comparators.js"; /** * A priority queue implemented with a binary heap. The heap is in descending * order by default, using JavaScript's built-in comparison operators to sort * the values. * * | Method | Average Case | Worst Case | * | ----------- | ------------ | ---------- | * | peek() | O(1) | O(1) | * | pop() | O(log n) | O(log n) | * | push(value) | O(1) | O(log n) | * * @example * ```ts * import { * ascend, * BinaryHeap, * descend, * } from "https://deno.land/std@$STD_VERSION/collections/binary_heap.ts"; * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * const maxHeap = new BinaryHeap(); * maxHeap.push(4, 1, 3, 5, 2); * assertEquals(maxHeap.peek(), 5); * assertEquals(maxHeap.pop(), 5); * assertEquals([...maxHeap], [4, 3, 2, 1]); * assertEquals([...maxHeap], []); * * const minHeap = new BinaryHeap(ascend); * minHeap.push(4, 1, 3, 5, 2); * assertEquals(minHeap.peek(), 1); * assertEquals(minHeap.pop(), 1); * assertEquals([...minHeap], [2, 3, 4, 5]); * assertEquals([...minHeap], []); * * const words = new BinaryHeap((a, b) => descend(a.length, b.length)); * words.push("truck", "car", "helicopter", "tank"); * assertEquals(words.peek(), "helicopter"); * assertEquals(words.pop(), "helicopter"); * assertEquals([...words], ["truck", "tank", "car"]); * assertEquals([...words], []); * ``` */ export declare class BinaryHeap implements Iterable { #private; private compare; constructor(compare?: (a: T, b: T) => number); /** Returns the underlying cloned array in arbitrary order without sorting */ toArray(): T[]; /** Creates a new binary heap from an array like or iterable object. */ static from(collection: ArrayLike | Iterable | BinaryHeap): BinaryHeap; static from(collection: ArrayLike | Iterable | BinaryHeap, options: { compare?: (a: T, b: T) => number; }): BinaryHeap; static from(collection: ArrayLike | Iterable | BinaryHeap, options: { compare?: (a: U, b: U) => number; map: (value: T, index: number) => U; thisArg?: V; }): BinaryHeap; /** The amount of values stored in the binary heap. */ get length(): number; /** Returns the greatest value in the binary heap, or undefined if it is empty. */ peek(): T | undefined; /** Removes the greatest value from the binary heap and returns it, or null if it is empty. */ pop(): T | undefined; /** Adds values to the binary heap. */ push(...values: T[]): number; /** Removes all values from the binary heap. */ clear(): void; /** Checks if the binary heap is empty. */ isEmpty(): boolean; /** Returns an iterator for retrieving and removing values from the binary heap. */ drain(): IterableIterator; [Symbol.iterator](): IterableIterator; }