require.mx('mxjs/base/algorithms/xheap.js');
This library provides a priority queue (heap) implementation
Status | Name |
---|---|
Heap createHeap
(
Function ↓cmp_function
)
Returns a Heap object, which encapsulates a priority queue. |
|
Array heapSort
(
Array ⇅array,
Number ↓start,
Number ↓end,
Function ↓cmp_function
)
Sorts an array using heapsort. |
Sorts an array using heapsort.
Parameters:Array
⇅array - - array to sortNumber
↓start - - index of array to start sorting at.Number
↓end - - 1 + index of array to stop sorting at.Function
↓cmp_function - - optional, function f(a,b) which returns positive if a > b, 0 if a = b and negative if a < b. If omitted, sorts as numbers.Array
⇅array A Heap encapsulates a priority queue
Status | Name |
---|---|
add
(
Number ↓value
)
Adds the specified value to the heap |
|
Number remove
(
)
Removes and returns the largest (by compare function) value in the heap. |
|
Number size
(
)
Returns the current size of this heap. |
Adds the specified value to the heap
Parameters:Number
↓value - - the value to add to the heapRemoves and returns the largest (by compare function) value in the heap.
Parameters:Number
↑value - - the returned value