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.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
elements | Array | <optional> | null | Contains the elements for the Heap. |
accessor | function | <optional> | (d) => d | Function returns the value of the element. |
comparator | "min" | | <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) |
- Source
- Type:
- Heap
Members
empty
Returns false if the the heap has entries, true if the heap has no entries.
- Source
first
Returns the top entry of the heap without removing it.
- Source
length
The size of the heap.
- Source
Methods
(static) heapify(elements, accessoropt, comparatoropt) → {Heap}
Creates a Heap from an Array
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
elements | Array | | Contains the elements for the Heap. | ||
accessor | function | <optional> | (d) => d | Function returns the value of the element. |
comparator | String | | <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) |
- Source
- Type:
- Heap
data() → {Array}
Returns elements of container array.
- Source
Array consisting the elements.
- Type:
- Array
(generator) iterate() → {Object}
Yields the raw data
- Source
Object consists of the element and its value (computed by accessor
).
- Type:
- Object
pop() → {Object}
Removes and returns the top entry of the heap.
- Source
Object consists of the element and its value (computed by accessor
).
- Type:
- Object
push(element) → {Heap}
Pushes the element to the heap.
Name | Type | Description |
---|---|---|
element |
- Source
- Type:
- Heap
raw_data() → {Array}
Returns the container array.
- Source
The container array.
- Type:
- Array
toArray() → {Array}
Returns the heap as ordered array.
- Source
Array consisting the elements ordered by comparator
.
- Type:
- Array