@utilityjs/heap
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Heap

An implementation of abstract Heap class.

license npm latest package npm downloads types

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;
}

Package Sidebar

Install

npm i @utilityjs/heap

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

14.4 kB

Total Files

8

Last publish

Collaborators

  • mimshins