
public abstract class DoubleHeap extends AbstractHeap
| Modifier and Type | Field and Description |
|---|---|
protected double[] |
queue
Heap storage: queue
|
DEFAULT_INITIAL_CAPACITY, modCount, size, validSize| Constructor and Description |
|---|
DoubleHeap(int size)
Constructor with initial capacity.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(double key)
Add a key-value pair to the heap
|
void |
add(double key,
int max)
Add a key-value pair to the heap, except if the new element is larger than
the top, and we are at design size (overflow)
|
void |
clear()
Delete all elements from the heap.
|
protected abstract boolean |
comp(double o1,
double o2)
Compare two objects
|
protected void |
ensureValid()
Repair the heap
|
protected boolean |
heapifyDown(int ipos,
double curkey)
Execute a "Heapify Downwards" aka "SiftDown".
|
protected void |
heapifyUp(int pos,
double curkey)
Execute a "Heapify Upwards" aka "SiftUp".
|
double |
peek()
Get the current top key
|
double |
poll()
Remove the first element
|
protected double |
removeAt(int pos)
Remove the element at the given position.
|
double |
replaceTopElement(double e)
Combined operation that removes the top element, and inserts a new element
instead.
|
protected void |
resize(int requiredSize)
Test whether we need to resize to have the requested capacity.
|
desiredSize, heapModified, sizepublic DoubleHeap(int size)
size - initial capacitypublic void add(double key)
key - Keypublic void add(double key,
int max)
key - Keymax - Maximum size of heappublic double replaceTopElement(double e)
e - New element to insertpublic double peek()
public double poll()
protected void ensureValid()
protected double removeAt(int pos)
pos - Element position.protected void heapifyUp(int pos,
double curkey)
pos - insertion positioncurkey - Current keyprotected boolean heapifyDown(int ipos,
double curkey)
ipos - re-insertion positioncurkey - Current keyprotected final void resize(int requiredSize)
requiredSize - required capacitypublic void clear()
clear in class AbstractHeapprotected abstract boolean comp(double o1,
double o2)