Kind: global class
- Heap
- new Heap(other, comparator)
- instance
- .peek() ⇒
*
- .push(el) ⇒
this
- .pop() ⇒
*
- .toArray() ⇒
Array
- .size() ⇒
number
- .isEmpty() ⇒
boolean
- .peek() ⇒
- static
- .heapify(arr, cmp) ⇒
Object
- .merge(h1, h2, comparator) ⇒
Heap
- .heapify(arr, cmp) ⇒
Creates a new Heap according to the arguments passed
Returns: Heap
- The new heap instance
Param | Type | Description |
---|---|---|
other | Object | Heap | function |
Can be an Array like Object of which all elements will be added to the Heap, another heap instance or just a custom comparator function. |
comparator | function |
If other is an Array like Object or another heap the custom comparator can always be passed as as second argument. |
Returns the first element in the heap
Kind: instance method of Heap
Returns: *
- The first element in the heap
Pushes a new element onto the heap
Kind: instance method of Heap
Returns: this
- The heap instance
Param | Type | Description |
---|---|---|
el | * |
The new element to be pushed |
Pops the first element from the heap
Kind: instance method of Heap
Returns: *
- The first element from the heap
Returns an array representation of the heap
Kind: instance method of Heap
Returns: Array
- The array representation of the heap
Returns the number of elements in the heap
Kind: instance method of Heap
Returns: number
- The size of the heap
Returns true if the heap is empty
Kind: instance method of Heap
Returns: boolean
- True if heap is empty. False otherwise
Modifies an Array like Object in place such that it satisfies the heap property
Kind: static method of Heap
Returns: Object
- The original Array like Object
Param | Type | Description |
---|---|---|
arr | Object |
An Array like Object |
cmp | function |
An optional comparator function |
Heap.merge(h1, h2, comparator) ⇒ Heap
Merges two heaps into a new heap.
Kind: static method of Heap
Returns: Heap
- The new merged heap
Param | Type | Description |
---|---|---|
h1 | Heap |
The first heap |
h2 | Heap |
The second heap |
comparator | function |
A custom comparator function |