dastal
Version:
Data Structures & Algorithms implementations
60 lines (59 loc) • 1.93 kB
TypeScript
import { CompareFn } from '..';
import { Heap } from './heap';
/**
* A binary heap is a heap implemented as a binary tree with an additional shape property
* ([source](https://en.wikipedia.org/wiki/Binary_heap)).
*
* **Shape property**: Must be a complete binary tree. This means all levels of the tree
* (except possibly the last one) are fully filled. If the last level of the tree is incomplete,
* the nodes of that level are filled from left to right.
*
* #### Complexity
*
* | Property | Average | Worst |
* | :------- | :------ | :---- |
* | Space | O(n) | O(n)
* | Push | O(1) | O(log n)
* | Peek | O(1) | O(1)
* | Pop | O(log n)| O(log n)
* | Search | O(n) | O(n)
*/
export declare class BinaryHeap<T> implements Heap<T> {
/**
* The array containing every element.
*/
protected array: T[];
/**
* The function to determine the order of elements.
*/
protected compare: CompareFn<T>;
/**
* Instantiate a heap.
*
* @param compareFn - The function to determine the order of elements.
* @param elements - A set of elements to initialize the list with.
*/
constructor(compareFn: CompareFn<T>, elements?: Iterable<T>);
addAll(elements: Iterable<T>): number;
clear(): void;
comparator(): CompareFn<T>;
contains(element: T): boolean;
delete(element: T): boolean;
merge(heap: Heap<T>): this;
peek(): T | undefined;
pop(): T | undefined;
push(value: T): number;
pushPop(value: T): T;
replace(value: T): T | undefined;
get size(): number;
sorted(): Iterable<T>;
/**
* Receive an iterator through the list.
*
* **Note:** Unexpected behavior can occur if the collection is modified during iteration.
*
* @returns An iterator through the list
*/
[Symbol.iterator](): Iterator<T>;
update(curElement: T, newElement: T): boolean;
}