Heap

Heap

Creates heaps.

Constructor

new Heap($compare)

Description:
  • Creates a new heap.
Source:
Examples
// without chaining
const heap = new Heap(compare);
heap.push(four);
heap.push(one);
heap.push(two);

const maximum = heap.pop();
// with chaining
const heap = new Heap(compare).push(four).push(one).push(two);

const maximum = heap.pop();
Parameters:
Name Type Description
$compare TypeHandlerCompare.<TypeGeneric> The compare handler.

Members

size :number

Description:
  • Gets the size of the heap.
Source:
Gets the size of the heap.
Type:
  • number

Methods

pop() → {TypeGeneric|undefined}

Description:
  • Pops an item.
Source:
Returns:
Type
TypeGeneric | undefined

push($item) → {this}

Description:
  • Pushes an item.
Source:
Parameters:
Name Type Description
$item TypeGeneric The item to push.
Returns:
Type
this

Type Definitions

(protected) TypeHandlerCompare($a, $b) → {number}

Source:
Parameters:
Name Type Description
$a TypeGeneric The first item to compare.
$b TypeGeneric The second item to compare.
Returns:
Type
number