datastructure Heap

new Heap(elementsopt, accessoropt, comparatoropt) → {Heap}

A heap is a datastructure holding its elements in a specific way, so that the top element would be the first entry of an ordered list.

Parameters:
NameTypeAttributesDefaultDescription
elementsArray<optional>
null

Contains the elements for the Heap. elements can be null.

accessorfunction<optional>
(d) => d

Function returns the value of the element.

comparator"min" | "max" | function<optional>
"min"

Function returning true or false defining the wished order of the Heap, or String for predefined function. ("min" for a Min-Heap, "max" for a Max_heap)

Returns:
Type: 
Heap

Members

empty

Returns false if the the heap has entries, true if the heap has no entries.

first

Returns the top entry of the heap without removing it.

length

The size of the heap.

Methods

(static) heapify(elements, accessoropt, comparatoropt) → {Heap}

Creates a Heap from an Array

Parameters:
NameTypeAttributesDefaultDescription
elementsArray | Set

Contains the elements for the Heap.

accessorfunction<optional>
(d) => d

Function returns the value of the element.

comparatorString | function<optional>
"min"

Function returning true or false defining the wished order of the Heap, or String for predefined function. ("min" for a Min-Heap, "max" for a Max_heap)

Returns:
Type: 
Heap

data() → {Array}

Returns elements of container array.

Returns:

Array consisting the elements.

Type: 
Array

(generator) iterate() → {Object}

Yields the raw data

Yields:

Object consists of the element and its value (computed by accessor).

Type: 
Object

pop() → {Object}

Removes and returns the top entry of the heap.

Returns:

Object consists of the element and its value (computed by accessor).

Type: 
Object

push(element) → {Heap}

Pushes the element to the heap.

Parameters:
NameTypeDescription
element
Returns:
Type: 
Heap

raw_data() → {Array}

Returns the container array.

Returns:

The container array.

Type: 
Array

toArray() → {Array}

Returns the heap as ordered array.

Returns:

Array consisting the elements ordered by comparator.

Type: 
Array