Skip to content

Latest commit

 

History

History
104 lines (75 loc) · 3.59 KB

API.md

File metadata and controls

104 lines (75 loc) · 3.59 KB

Heap

Kind: global class

new Heap(other, comparator)

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.

heap.peek() ⇒ *

Returns the first element in the heap

Kind: instance method of Heap
Returns: * - The first element in the heap

heap.push(el) ⇒ this

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

heap.pop() ⇒ *

Pops the first element from the heap

Kind: instance method of Heap
Returns: * - The first element from the heap

heap.toArray() ⇒ Array

Returns an array representation of the heap

Kind: instance method of Heap
Returns: Array - The array representation of the heap

heap.size() ⇒ number

Returns the number of elements in the heap

Kind: instance method of Heap
Returns: number - The size of the heap

heap.isEmpty() ⇒ boolean

Returns true if the heap is empty

Kind: instance method of Heap
Returns: boolean - True if heap is empty. False otherwise

Heap.heapify(arr, cmp) ⇒ Object

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