Skip to content

darblast/heap

Repository files navigation

@darblast/heap

License: MIT Node.js CI

Provides algorithms to manipulate binary heap arrays.

See https://en.wikipedia.org/wiki/Binary_heap for more information.

Three versions of each function are provided:

  • the ones suffixed with Cmp take an arbitrary comparison function;
  • the ones suffixed with Min use the < operator and result in a min-heap;
  • the ones suffixed with Max use the > operator and result in a max-heap.

The comparison function must be the same across calls to different algorithms on the same array, otherwise the results will be inconsistent. It has the following signature:

export type CompareFn<Element> = (lhs: Element, rhs: Element) => boolean;