Class ComparatorMaxHeap<K>
- java.lang.Object
 - 
- elki.utilities.datastructures.heap.ComparatorMaxHeap<K>
 
 
- 
- Type Parameters:
 K- Key type
- All Implemented Interfaces:
 ObjectHeap<K>
public class ComparatorMaxHeap<K> extends java.lang.Object implements ObjectHeap<K>
Binary heap for primitive types.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 classComparatorMaxHeap.UnsortedIterUnsorted iterator - in heap order. 
- 
Field Summary
Fields Modifier and Type Field Description protected java.util.Comparator<java.lang.Object>comparatorComparatorprotected intsizeCurrent size of heap.private static intTWO_HEAP_INITIAL_SIZEInitial size of the 2-ary heap.protected java.lang.Object[]twoheapBase heap. 
- 
Constructor Summary
Constructors Constructor Description ComparatorMaxHeap(int minsize, java.util.Comparator<? super K> comparator)Constructor, with given minimum size.ComparatorMaxHeap(java.util.Comparator<? super K> comparator)Constructor, with default size. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(K o)Add a key-value pair to the heapvoidadd(K 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)voidclear()Delete all elements from the heap.private voidheapifyDown(java.lang.Object cur)Invoke heapify-down for the root object.private voidheapifyUp(int twopos, java.lang.Object cur)Heapify-Up method for 2-ary heap.booleanisEmpty()Is the heap empty?Kpeek()Get the current top keyKpoll()Remove the first elementKreplaceTopElement(K reinsert)Combined operation that removes the top element, and inserts a new element instead.intsize()Query the sizejava.lang.StringtoString()ComparatorMaxHeap.UnsortedIterunsortedIter()Get an unsorted iterator to inspect the heap. 
 - 
 
- 
- 
Field Detail
- 
twoheap
protected java.lang.Object[] twoheap
Base heap. 
- 
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
 
 
- 
comparator
protected java.util.Comparator<java.lang.Object> comparator
Comparator 
 - 
 
- 
Constructor Detail
- 
ComparatorMaxHeap
public ComparatorMaxHeap(java.util.Comparator<? super K> comparator)
Constructor, with default size.- Parameters:
 comparator- Comparator
 
- 
ComparatorMaxHeap
public ComparatorMaxHeap(int minsize, java.util.Comparator<? super K> comparator)Constructor, with given minimum size.- Parameters:
 minsize- Minimum sizecomparator- Comparator
 
 - 
 
- 
Method Detail
- 
clear
public void clear()
Description copied from interface:ObjectHeapDelete all elements from the heap.- Specified by:
 clearin interfaceObjectHeap<K>
 
- 
size
public int size()
Description copied from interface:ObjectHeapQuery the size- Specified by:
 sizein interfaceObjectHeap<K>- Returns:
 - Size
 
 
- 
isEmpty
public boolean isEmpty()
Description copied from interface:ObjectHeapIs the heap empty?- Specified by:
 isEmptyin interfaceObjectHeap<K>- Returns:
 truewhen the size is 0.
 
- 
add
public void add(K o)
Description copied from interface:ObjectHeapAdd a key-value pair to the heap- Specified by:
 addin interfaceObjectHeap<K>- Parameters:
 o- Key
 
- 
add
public void add(K key, int max)
Description copied from interface:ObjectHeapAdd a key-value pair to the heap, except if the new element is larger than the top, and we are at design size (overflow)- Specified by:
 addin interfaceObjectHeap<K>- Parameters:
 key- Keymax- Maximum size of heap
 
- 
replaceTopElement
public K replaceTopElement(K reinsert)
Description copied from interface:ObjectHeapCombined operation that removes the top element, and inserts a new element instead.- Specified by:
 replaceTopElementin interfaceObjectHeap<K>- Parameters:
 reinsert- New element to insert- Returns:
 - Previous top element of the heap
 
 
- 
heapifyUp
private void heapifyUp(int twopos, java.lang.Object cur)Heapify-Up method for 2-ary heap.- Parameters:
 twopos- Position in 2-ary heap.cur- Current object
 
- 
poll
public K poll()
Description copied from interface:ObjectHeapRemove the first element- Specified by:
 pollin interfaceObjectHeap<K>- Returns:
 - Top element
 
 
- 
heapifyDown
private void heapifyDown(java.lang.Object cur)
Invoke heapify-down for the root object.- Parameters:
 cur- Object to insert.
 
- 
peek
public K peek()
Description copied from interface:ObjectHeapGet the current top key- Specified by:
 peekin interfaceObjectHeap<K>- Returns:
 - Top key
 
 
- 
toString
public java.lang.String toString()
- Overrides:
 toStringin classjava.lang.Object
 
- 
unsortedIter
public ComparatorMaxHeap.UnsortedIter unsortedIter()
Description copied from interface:ObjectHeapGet an unsorted iterator to inspect the heap.- Specified by:
 unsortedIterin interfaceObjectHeap<K>- Returns:
 - Iterator
 
 
 - 
 
 -