
public abstract class IntegerHeap extends AbstractHeap
| Modifier and Type | Field and Description |
|---|---|
protected int[] |
queue
Heap storage: queue
|
DEFAULT_INITIAL_CAPACITY, modCount, size, validSize| Constructor and Description |
|---|
IntegerHeap(int size)
Constructor with initial capacity.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int key)
Add a key-value pair to the heap
|
void |
add(int 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(int o1,
int o2)
Compare two objects
|
protected void |
ensureValid()
Repair the heap
|
protected boolean |
heapifyDown(int ipos,
int curkey)
Execute a "Heapify Downwards" aka "SiftDown".
|
protected void |
heapifyUp(int pos,
int curkey)
Execute a "Heapify Upwards" aka "SiftUp".
|
int |
peek()
Get the current top key
|
int |
poll()
Remove the first element
|
protected int |
removeAt(int pos)
Remove the element at the given position.
|
int |
replaceTopElement(int 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 IntegerHeap(int size)
size - initial capacitypublic void add(int key)
key - Keypublic void add(int key,
int max)
key - Keymax - Maximum size of heappublic int replaceTopElement(int e)
e - New element to insertpublic int peek()
public int poll()
protected void ensureValid()
protected int removeAt(int pos)
pos - Element position.protected void heapifyUp(int pos,
int curkey)
pos - insertion positioncurkey - Current keyprotected boolean heapifyDown(int ipos,
int curkey)
ipos - re-insertion positioncurkey - Current keyprotected final void resize(int requiredSize)
requiredSize - required capacitypublic void clear()
clear in class AbstractHeapprotected abstract boolean comp(int o1,
int o2)