import * as utils from '../utils'; /******************************************************************************* * A min binary heap implements the Priority Queue ADT. It has constant access * to the min element of the heap, with logarithmic insertions and deletions. * * add(element) - O(logn) * poll() - O(logn) * peek() - O(1) * * For more info, refer to https://en.wikipedia.org/wiki/Binary_heap ******************************************************************************/ declare class MinBinaryHeap { private heap; private compare; constructor(elements?: Iterable, compareFunction?: utils.CompareFunction); private heapify; /***************************************************************************** INSPECTION *****************************************************************************/ /** * Returns the size of the heap - O(1) * @returns {number} */ size(): number; /** * Returns true if the heap is empty, false otherwise - O(1) * @returns {boolean} */ isEmpty(): boolean; /***************************************************************************** INSERTION/DELETION *****************************************************************************/ /** * Adds an element to the heap, while maintaing the heap invariant - O(log(n)) * @param {T} element * @returns {void} */ add(element: T): void; /** * Removes and returns top most element of heap - O(log(n)) * @returns {T} */ poll(): T | null; /** * Removes element if it exists. Returns true if success, false otherwise - O(n) * @param {T} element * @returns {boolean} */ remove(element: T): boolean; /** * Clears the heap - O(1) * @returns {void} */ clear(): void; /***************************************************************************** ACCESSING *****************************************************************************/ /** * Peeks at the top most element in the heap - O(1) * @returns {T} */ peek(): T | null; /***************************************************************************** SEARCHING *****************************************************************************/ /** * Returns true if element is in heap, false otherwise - O(n) * @param {T} element * @returns {boolean} */ contains(element: T): boolean; /***************************************************************************** HELPERS *****************************************************************************/ /** * Sinks element with index k until heap invariant is satisfied - O(log(n)) * O(log(n)) because in the worst case we sink the element down the entire * height of the tree * @param {number} k * @returns {void} */ private sink; /** * Swims an element with index k until heap invariant is satisfied - O(log(n)) * O(log(n)) because in the worst case we swim the element up the entire tree * @param {number} k * @returns {void} */ private swim; private swap; /** * Removes element at provided index by swapping it with last element, and * heapifying the swapped element by sinking/swimming it - O(log(n)). * * O(log(n)) because in worst case we swink/swim element throughout the entire tree * @param {number} indexToRemove * @returns {T} */ private removeAt; private getLeftChildIndex; private getRightChildIndex; private getParentIndex; /** * Returns true if a is less than b, false otherwise * @param {number} a * @param {number} b */ private less; } export default MinBinaryHeap; //# sourceMappingURL=min-binary-heap.d.ts.map