1.0.1 • Published 2 years ago

@utilityjs/max-heap v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

An implementation of MaxHeap data structure.

license npm latest package npm downloads types

npm i @utilityjs/max-heap | yarn add @utilityjs/max-heap

MaxHeap(compareFunction?)

class MaxHeap<T> {
  constructor(compareFunction?: CompareFunction<T>);
  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;
}