V
- value typepublic class DoubleObjMaxHeap<V> extends Object
Modifier and Type | Field and Description |
---|---|
private static int |
DEFAULT_INITIAL_CAPACITY
Default initial capacity
|
protected double[] |
keys
Heap storage: keys
|
int |
modCount
(Structural) modification counter.
|
protected int |
size
Current number of objects
|
protected int |
validSize
Indicate up to where the heap is valid
|
protected Object[] |
values
Heap storage: values
|
Constructor and Description |
---|
DoubleObjMaxHeap()
Default constructor: default capacity, natural ordering.
|
DoubleObjMaxHeap(int size)
Constructor with initial capacity and
Comparator . |
Modifier and Type | Method and Description |
---|---|
boolean |
add(double key,
V val)
Add a key-value pair to the heap
|
protected String |
checkHeap()
Test whether the heap is still valid.
|
void |
clear()
Delete all elements from the heap.
|
protected void |
ensureValid()
Repair the heap
|
protected boolean |
heapifyDown(int ipos,
double curkey,
Object curval)
Execute a "Heapify Downwards" aka "SiftDown".
|
protected void |
heapifyUp(int pos,
double curkey,
Object curval)
Execute a "Heapify Upwards" aka "SiftUp".
|
double |
peekKey()
Get the current top key
|
V |
peekValue()
Get the current top value
|
void |
poll()
Remove the first element
|
protected void |
removeAt(int pos)
Remove the element at the given position.
|
protected void |
resize(int requiredSize)
Test whether we need to resize to have the requested capacity.
|
int |
size()
Query the size
|
protected double[] keys
protected Object[] values
protected int size
protected int validSize
public transient int modCount
private static final int DEFAULT_INITIAL_CAPACITY
public DoubleObjMaxHeap()
public DoubleObjMaxHeap(int size)
Comparator
.size
- initial capacitypublic boolean add(double key, V val)
key
- Keyval
- Valuepublic double peekKey()
public V peekValue()
public void poll()
protected void ensureValid()
protected void removeAt(int pos)
pos
- Element position.protected void heapifyUp(int pos, double curkey, Object curval)
pos
- insertion positioncurkey
- Current keycurval
- Current valueprotected boolean heapifyDown(int ipos, double curkey, Object curval)
ipos
- re-insertion positioncurkey
- Current keycurval
- Current valuepublic int size()
protected final void resize(int requiredSize)
requiredSize
- required capacitypublic void clear()
protected String checkHeap()
null
when the heap is correct