new Heap([cmpFunc])
Binary heap container.
- Source:
- ./src/modules/Heap.js, line 14
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
cmpFunc |
function(*, *): boolean |
<optional> |
A comparison function which returns whether it's first argument is less than the second argument. If this argument is not provided, then the `<` operator will be used. |
Methods
-
<private> _siftDown(startPos, pos)
-
Sift down the possibly out-of-order value.
- Source:
- ./src/modules/Heap.js, line 138
Parameters:
Name Type Description startPos
number Start index of the array as a heap. pos
number Index of the leaf with possiblly out-of-order value. -
<private> _siftUp(pos)
-
Sift up the possibly out-of-order value.
- Source:
- ./src/modules/Heap.js, line 167
Parameters:
Name Type Description pos
number Index of leaf with possibly out-of-order value. -
heapify()
-
Heapify the heap. This method may be used when the internal data is modified.
- Source:
- ./src/modules/Heap.js, line 124
-
isEmpty() → {boolean}
-
Determine whether the heap is empty.
- Source:
- ./src/modules/Heap.js, line 52
Returns:
- Type
- boolean
-
pop()
-
Pop the smallest item off the heap.
- Source:
- ./src/modules/Heap.js, line 70
-
push(item)
-
Push an item onto the heap.
- Source:
- ./src/modules/Heap.js, line 61
Parameters:
Name Type Description item
* Item to push onto the heap. -
pushpop(item)
-
Fast version of a push followed by a pop.
- Source:
- ./src/modules/Heap.js, line 107
Parameters:
Name Type Description item
* Item to be pushed onto the heap. -
replace(item)
-
Pop and return the current smallest value, and add the new item. This is more efficient than `pop()` followed by `push()`, and can be more appropriate when using a fixed-size heap. Note that the value returned may be larger than the pushed item!
- Source:
- ./src/modules/Heap.js, line 95
Parameters:
Name Type Description item
* Item to replace the top one of the heap. -
size() → {number}
-
Get the size of the heap.
- Source:
- ./src/modules/Heap.js, line 43
Returns:
The number of items in the heap.- Type
- number
-
top()
-
Get the top(smallest) item from the heap.
- Source:
- ./src/modules/Heap.js, line 34