Heap

Heap

Creates a Min Heap data structure. Implemented as a ES6 Class to fix prototyping documentation and properly encapsulate internal mechanics.

Constructor

new Heap(valFnopt)

Description:
  • Initializes the Heap class object.
Source:
Parameters:
Name Type Attributes Description
valFn function <optional>
A function to extract the comparison value from an element. Defaults to identity (n => n).

Classes

Heap

Methods

add(el) → {number}

Description:
  • Adds an element to the heap.
Source:
Parameters:
Name Type Description
el * The element to add.
Returns:
The new index of the added element.
Type
number

data() → {Array}

Description:
  • Returns the internal array representation of the heap (excluding the dummy first element).
Source:
Returns:
The heap elements.
Type
Array

size() → {number}

Description:
  • Returns the number of elements in the heap.
Source:
Returns:
The size of the heap.
Type
number

take() → {*}

Description:
  • Removes and returns the minimum element (root) from the heap.
Source:
Returns:
The minimum element.
Type
*