Heap instance constructor.
Optional comparison function, defaults to Heap.minComparator
Optional comparison function, defaults to Heap.minComparator
Alias of peek
Alias of add
Alias of pop
Length of the heap.
Get length limit of the heap.
Set length limit of the heap.
Iterator interface
Limit heap size if needed
Return the bottom (lowest value) N elements of the heap, without corner cases, unsorted
Number of elements.
Array of length <= N.
Returns the inverse to the comparison function.
Move a node to a new index, switching places
First node index
Another node index
Move a node down the tree (to the leaves) to find a place where the heap is sorted.
Index of the node
Move a node up the tree (to the root) to find a place where the heap is sorted.
Index of the node
Return index of the top element
Return the top (highest value) N elements of the heap, without corner cases, unsorted Implementation: init + push.
Number of elements.
Array of length <= N.
Return the top (highest value) N elements of the heap, without corner cases, unsorted Implementation: heap.
Number of elements.
Array of length <= N.
Return the top (highest value) N elements of the heap, without corner cases, unsorted Implementation: push.
Number of elements.
Array of length <= N.
Return the top element
Adds an element to the heap. Aliases: offer.
Same as: push(element)
Element to be added
true
Adds an array of elements to the heap. Similar as: push(element, element, ...).
Elements to be added
true
Return the bottom (lowest value) N elements of the heap.
Number of elements.
Array of length <= N.
Check if the heap is sorted, useful for testing purposes.
Returns an element if something wrong is found, otherwise it's undefined
Remove all of the elements from this heap.
Clone this heap
Returns the comparison function.
Returns true if this queue contains the specified element.
Element to be found
Optional comparison function, receives (element, needle)
Get the element at the given index.
Index to get
Element at that index
Get the elements of these node's children
Node index
Children elements
Get the element of this node's parent
Node index
Parent element
Initialise a heap, sorting nodes
Optional initial state array
Test if the heap has no elements.
True if no elements on the heap
Returns an iterator. To comply with Java interface.
Get the leafs of the tree (no children nodes)
Top node. Aliases: element.
Same as: top(1)[0]
Top node
Extract the top node (root). Aliases: poll.
Extracted top node, undefined if empty
Pushes element(s) to the heap.
Elements to insert
True if elements are present
Same as push & pop in sequence, but faster
Element to insert
Extracted top node
Pop the current peek value, and add the new item.
Element to replace peek
Old peek
Size of the heap
Clone the heap's internal array
String output, call to Array.prototype.toString()
Return the top (highest value) N elements of the heap.
Number of elements.
Array of length <= N.
Default equality function.
First element
Second element
True if equal, false otherwise
Gets children indices for given index.
Parent index
Array of children indices
Gets parent index for given index.
Children index
Parent index, -1 if idx is 0
Gets sibling index for given index.
Children index
Sibling index, -1 if idx is 0
Return the n least valuable elements of a heap-like Array
Array, should be an array-heap
Max number of elements
Optional compare function
Elements
Converts an array into an array-heap, in place
Array to be modified
Optional compare function
For convenience, it returns a Heap instance
Extract the peek of an array-heap
Array to be modified, should be a heap
Optional compare function
Returns the extracted peek
Pushes a item into an array-heap
Array to be modified, should be a heap
Item to push
Optional compare function
Push followed by pop, faster
Array to be modified, should be a heap
Item to push
Optional compare function
Returns the extracted peek
Replace peek with item
Array to be modified, should be a heap
Item as replacement
Optional compare function
Returns the extracted peek
Return the n most valuable elements of a heap-like Array
Array, should be an array-heap
Max number of elements
Optional compare function
Elements
Max heap comparison function.
First element
Second element
0 if they're equal, positive if a goes up, negative if b goes up
Max number heap comparison function.
First element
Second element
0 if they're equal, positive if a goes up, negative if b goes up
Min heap comparison function, default.
First element
Second element
0 if they're equal, positive if a goes up, negative if b goes up
Min number heap comparison function, default.
First element
Second element
0 if they're equal, positive if a goes up, negative if b goes up
Return the n most valuable elements of an iterable
Max number of elements
Optional compare function
Elements
Return the n least valuable elements of an iterable
Max number of elements
Optional compare function
Elements
Prints a heap.
Heap to be printed
Generated using TypeDoc
Heap