typescript-ds-lib
Version:
A collection of TypeScript data structure implementations
37 lines (36 loc) • 942 B
TypeScript
import { Comparator } from '../types';
import { BaseCollection } from './base-collection';
export interface Heap<T> {
push(element: T): void;
pop(): T | undefined;
top(): T | undefined;
}
export declare class Heap<T> extends BaseCollection<T> implements Heap<T> {
private items;
private comparator;
constructor(comparator?: Comparator<T>);
/**
* Checks if the heap is empty. Returns true if empty, false otherwise.
*/
isEmpty(): boolean;
/**
* Returns the number of elements in the heap.
*/
size(): number;
/**
* Removes all elements from the heap.
*/
clear(): void;
/**
* Moves an element up the heap to its correct position.
*/
private heapifyUp;
/**
* Moves an element down the heap to its correct position.
*/
private heapifyDown;
/**
* Checks if two heaps are equal.
*/
equals(other: Heap<T>): boolean;
}