V - Value typepublic class IntegerObjectMinHeap<V> extends java.lang.Object implements IntegerObjectHeap<V>
| Modifier and Type | Class and Description |
|---|---|
private class |
IntegerObjectMinHeap.UnsortedIter
Unsorted iterator - in heap order.
|
| Modifier and Type | Field and Description |
|---|---|
protected int |
size
Current size of heap.
|
private static int |
TWO_HEAP_INITIAL_SIZE
Initial size of the 2-ary heap.
|
protected int[] |
twoheap
Base heap.
|
protected java.lang.Object[] |
twovals
Base heap values.
|
| Constructor and Description |
|---|
IntegerObjectMinHeap()
Constructor, with default size.
|
IntegerObjectMinHeap(int minsize)
Constructor, with given minimum size.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int o,
V v)
Add a key-value pair to the heap
|
void |
add(int key,
V val,
int max)
Add a key-value pair to the heap if it improves the top.
|
void |
clear()
Clear the heap contents.
|
boolean |
containsKey(int q)
Contains operation for a key (slow: with a linear scan).
|
boolean |
containsValue(V q)
Contains operation for a value (slow: with a linear scan).
|
private void |
heapifyDown(int cur,
java.lang.Object val)
Invoke heapify-down for the root object.
|
private void |
heapifyUp(int twopos,
int cur,
java.lang.Object val)
Heapify-Up method for 2-ary heap.
|
boolean |
isEmpty()
Is the heap empty?
|
int |
peekKey()
Get the current top key.
|
V |
peekValue()
Get the current top value.
|
void |
poll()
Remove the first element.
|
void |
replaceTopElement(int reinsert,
V val)
Combined operation that removes the top element, and inserts a new element instead.
|
int |
size()
Query the size.
|
java.lang.String |
toString() |
IntegerObjectMinHeap.UnsortedIter |
unsortedIter()
Get an unsorted iterator to inspect the heap.
|
protected int[] twoheap
protected java.lang.Object[] twovals
protected int size
private static final int TWO_HEAP_INITIAL_SIZE
public IntegerObjectMinHeap()
public IntegerObjectMinHeap(int minsize)
minsize - Minimum sizepublic void clear()
IntegerObjectHeapclear in interface IntegerObjectHeap<V>public int size()
IntegerObjectHeapsize in interface IntegerObjectHeap<V>public boolean isEmpty()
IntegerObjectHeapisEmpty in interface IntegerObjectHeap<V>true when the size is 0.public void add(int o,
V v)
IntegerObjectHeapadd in interface IntegerObjectHeap<V>o - Keyv - Valuepublic void add(int key,
V val,
int max)
IntegerObjectHeapadd in interface IntegerObjectHeap<V>key - Keyval - Valuemax - Desired maximum sizepublic void replaceTopElement(int reinsert,
V val)
IntegerObjectHeapreplaceTopElement in interface IntegerObjectHeap<V>reinsert - Key of new elementval - Value of new elementprivate void heapifyUp(int twopos,
int cur,
java.lang.Object val)
twopos - Position in 2-ary heap.cur - Current objectval - Current valuepublic void poll()
IntegerObjectHeappoll in interface IntegerObjectHeap<V>private void heapifyDown(int cur,
java.lang.Object val)
cur - Object to insert.val - Value to reinsert.public int peekKey()
IntegerObjectHeappeekKey in interface IntegerObjectHeap<V>public V peekValue()
IntegerObjectHeappeekValue in interface IntegerObjectHeap<V>public boolean containsKey(int q)
IntegerObjectHeapcontainsKey in interface IntegerObjectHeap<V>q - Keytrue if the key is contained in the heap.public boolean containsValue(V q)
IntegerObjectHeapcontainsValue in interface IntegerObjectHeap<V>q - Valuetrue if the value is contained in the heap.public java.lang.String toString()
toString in class java.lang.Objectpublic IntegerObjectMinHeap.UnsortedIter unsortedIter()
IntegerObjectHeapunsortedIter in interface IntegerObjectHeap<V>Copyright © 2019 ELKI Development Team. License information.