Constructor
new Heap(items, func)
Create a new Heap.
Parameters:
Name | Type | Description |
---|---|---|
items | Array.<any> | Items to add |
func | function | Function for comparing two items |
- Source
Methods
add(item)
Add an item to the heap. Will append the item to the end of the array and heapify after.
Parameters:
Name | Type | Description |
---|---|---|
item | any | Item to add |
- Source
hasCustom(func) → {boolean}
Check if a value exists in the Heap, using a specific function. Because of the custom function, the search must be done by iterating over every single value in the raw array.
Parameters:
Name | Type | Description |
---|---|---|
func | function | Function to check with |
- Source
Returns:
Whether or not the Heap contains a value fulfilling the requirements of the custom function
- Type:
- boolean
peek() → {any}
Peek at the root value of the Heap.
- Source
Returns:
Root value of the Heap
- Type:
- any
pop() → {any}
Pop the root of the Heap. Will swap the last item with the root, remove the original, and heapify after.
- Source
Returns:
Root value of the Heap
- Type:
- any