@utilityjs/heap
v1.0.1
Published
An implementation of abstract Heap class.
Downloads
3
Maintainers
Readme
An implementation of abstract Heap class.
npm i @utilityjs/heap | yarn add @utilityjs/heap
Usage
This is an abstract class with a single abstract method (pairIsInCorrectOrder
).
This method checks if pair of heap elements is in correct order.
API
Heap(compareFunction?)
abstract class Heap<T> {
protected comparator: Comparator<T>;
constructor(compareFunction?: CompareFunction<T>);
abstract pairIsInCorrectOrder(
firstItem: T | null,
secondItem: T | null
): boolean;
getLeftChildIndex(parentIndex: number): number;
getRightChildIndex(parentIndex: number): number;
getParentIndex(childIndex: number): number;
hasParent(childIndex: number): boolean;
hasLeftChild(parentIndex: number): boolean;
hasRightChild(parentIndex: number): boolean;
getLeftChild(parentIndex: number): T | null;
getRightChild(parentIndex: number): T | null;
getParent(childIndex: number): T | null;
isEmpty(): boolean;
toString(): string;
peek(): T | null;
poll(): T | null;
add(item: T): void;
remove(item: T): void;
find(item: T): number[];
swap(index1: number, index2: number): void;
heapifyDown(startIndex?: number): void;
heapifyUp(startIndex?: number): void;
}