Class IntegerObjectMinHeap<V>
- java.lang.Object
-
- elki.utilities.datastructures.heap.IntegerObjectMinHeap<V>
-
- Type Parameters:
V- Value type
- All Implemented Interfaces:
IntegerObjectHeap<V>
public class IntegerObjectMinHeap<V> extends java.lang.Object implements IntegerObjectHeap<V>
Binary heap for int keys and Object values.This class is generated from a template.
- Since:
- 0.6.0
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classIntegerObjectMinHeap.UnsortedIterUnsorted iterator - in heap order.
-
Field Summary
Fields Modifier and Type Field Description protected intsizeCurrent size of heap.private static intTWO_HEAP_INITIAL_SIZEInitial size of the 2-ary heap.protected int[]twoheapBase heap.protected java.lang.Object[]twovalsBase heap values.
-
Constructor Summary
Constructors Constructor Description IntegerObjectMinHeap()Constructor, with default size.IntegerObjectMinHeap(int minsize)Constructor, with given minimum size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int o, V v)Add a key-value pair to the heapvoidadd(int key, V val, int max)Add a key-value pair to the heap if it improves the top.voidclear()Clear the heap contents.booleancontainsKey(int q)Contains operation for a key (slow: with a linear scan).booleancontainsValue(V q)Contains operation for a value (slow: with a linear scan).private voidheapifyDown(int cur, java.lang.Object val)Invoke heapify-down for the root object.private voidheapifyUp(int twopos, int cur, java.lang.Object val)Heapify-Up method for 2-ary heap.booleanisEmpty()Is the heap empty?intpeekKey()Get the current top key.VpeekValue()Get the current top value.voidpoll()Remove the first element.voidreplaceTopElement(int reinsert, V val)Combined operation that removes the top element, and inserts a new element instead.intsize()Query the size.java.lang.StringtoString()IntegerObjectMinHeap.UnsortedIterunsortedIter()Get an unsorted iterator to inspect the heap.
-
-
-
Field Detail
-
twoheap
protected int[] twoheap
Base heap.
-
twovals
protected java.lang.Object[] twovals
Base heap values.
-
size
protected int size
Current size of heap.
-
TWO_HEAP_INITIAL_SIZE
private static final int TWO_HEAP_INITIAL_SIZE
Initial size of the 2-ary heap.- See Also:
- Constant Field Values
-
-
Method Detail
-
clear
public void clear()
Description copied from interface:IntegerObjectHeapClear the heap contents.- Specified by:
clearin interfaceIntegerObjectHeap<V>
-
size
public int size()
Description copied from interface:IntegerObjectHeapQuery the size.- Specified by:
sizein interfaceIntegerObjectHeap<V>- Returns:
- Size
-
isEmpty
public boolean isEmpty()
Description copied from interface:IntegerObjectHeapIs the heap empty?- Specified by:
isEmptyin interfaceIntegerObjectHeap<V>- Returns:
truewhen the size is 0.
-
add
public void add(int o, V v)Description copied from interface:IntegerObjectHeapAdd a key-value pair to the heap- Specified by:
addin interfaceIntegerObjectHeap<V>- Parameters:
o- Keyv- Value
-
add
public void add(int key, V val, int max)Description copied from interface:IntegerObjectHeapAdd a key-value pair to the heap if it improves the top.- Specified by:
addin interfaceIntegerObjectHeap<V>- Parameters:
key- Keyval- Valuemax- Desired maximum size
-
replaceTopElement
public void replaceTopElement(int reinsert, V val)Description copied from interface:IntegerObjectHeapCombined operation that removes the top element, and inserts a new element instead.- Specified by:
replaceTopElementin interfaceIntegerObjectHeap<V>- Parameters:
reinsert- Key of new elementval- Value of new element
-
heapifyUp
private void heapifyUp(int twopos, int cur, java.lang.Object val)Heapify-Up method for 2-ary heap.- Parameters:
twopos- Position in 2-ary heap.cur- Current objectval- Current value
-
poll
public void poll()
Description copied from interface:IntegerObjectHeapRemove the first element.- Specified by:
pollin interfaceIntegerObjectHeap<V>
-
heapifyDown
private void heapifyDown(int cur, java.lang.Object val)Invoke heapify-down for the root object.- Parameters:
cur- Object to insert.val- Value to reinsert.
-
peekKey
public int peekKey()
Description copied from interface:IntegerObjectHeapGet the current top key.- Specified by:
peekKeyin interfaceIntegerObjectHeap<V>- Returns:
- Top key
-
peekValue
public V peekValue()
Description copied from interface:IntegerObjectHeapGet the current top value.- Specified by:
peekValuein interfaceIntegerObjectHeap<V>- Returns:
- Value
-
containsKey
public boolean containsKey(int q)
Description copied from interface:IntegerObjectHeapContains operation for a key (slow: with a linear scan).- Specified by:
containsKeyin interfaceIntegerObjectHeap<V>- Parameters:
q- Key- Returns:
trueif the key is contained in the heap.
-
containsValue
public boolean containsValue(V q)
Description copied from interface:IntegerObjectHeapContains operation for a value (slow: with a linear scan).- Specified by:
containsValuein interfaceIntegerObjectHeap<V>- Parameters:
q- Value- Returns:
trueif the value is contained in the heap.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
unsortedIter
public IntegerObjectMinHeap.UnsortedIter unsortedIter()
Description copied from interface:IntegerObjectHeapGet an unsorted iterator to inspect the heap.- Specified by:
unsortedIterin interfaceIntegerObjectHeap<V>- Returns:
- Iterator
-
-