Package elki.database.ids.integer
Class DoubleIntegerDBIDHeap
- java.lang.Object
-
- elki.database.ids.integer.DoubleIntegerDBIDHeap
-
- All Implemented Interfaces:
DBIDRef,DoubleDBIDHeap
- Direct Known Subclasses:
DoubleIntegerDBIDKNNHeap
class DoubleIntegerDBIDHeap extends java.lang.Object implements DoubleDBIDHeap
Wrapper around a primitive heap to handle DBIDs.- Since:
- 0.8.0
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classDoubleIntegerDBIDHeap.UnorderedIterIterate over all objects in the heap, not ordered.
-
Field Summary
Fields Modifier and Type Field Description private DoubleIntegerHeapheapThe main heap.
-
Constructor Summary
Constructors Modifier Constructor Description protectedDoubleIntegerDBIDHeap(DoubleIntegerHeap heap)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear the heap.booleancontains(DBIDRef o)Check if an object is already in the heap (slow scan).doubleinsert(double distance, DBIDRef id)Add a double-id pair to the heapdoubleinsert(double distance, DBIDRef id, int max)Add a double-id pair to the heap unless the heap grows beyond the given maximum size.intinternalGetIndex()Internal only: Get the internal index.booleanisEmpty()Test if the heap is empty.doublepeekKey()Get the topmost value (the heap is aDBIDRef, referencing the top element).voidpoll()Remove the topmost element.voidreplaceTopElement(double distance, DBIDRef id)Replace the top element.intsize()Current size of heap.java.lang.StringtoString()DoubleDBIDIterunorderedIterator()Unordered iterator over the heap.
-
-
-
Field Detail
-
heap
private final DoubleIntegerHeap heap
The main heap.
-
-
Constructor Detail
-
DoubleIntegerDBIDHeap
protected DoubleIntegerDBIDHeap(DoubleIntegerHeap heap)
Constructor.- Parameters:
heap- Heap to use
-
-
Method Detail
-
insert
public double insert(double distance, DBIDRef id)Description copied from interface:DoubleDBIDHeapAdd a double-id pair to the heap- Specified by:
insertin interfaceDoubleDBIDHeap- Parameters:
distance- Key valueid- ID number- Returns:
- Value of to the element at the top of the heap
-
insert
public double insert(double distance, DBIDRef id, int max)Description copied from interface:DoubleDBIDHeapAdd a double-id pair to the heap unless the heap grows beyond the given maximum size. Beware of the following subtle details:- If the heap has fewer than "max" elements, the value is added.
- else, if the new value is "worse" than the top, it will replace the top (and the heap will be repaired)
- for a min heap, this adds only larger value, for a max heap only smaller values. This may seem odd, but it is equivalent to adding the new element and then removing the top ("best") element.
- But: the heap will not be reduced to the given size
- Specified by:
insertin interfaceDoubleDBIDHeap- Parameters:
distance- Distance valueid- ID numbermax- Maximum number of values- Returns:
- Distance to the element at the top of the heap
-
replaceTopElement
public void replaceTopElement(double distance, DBIDRef id)Replace the top element.- Parameters:
distance- New distanceid- New element
-
poll
public void poll()
Description copied from interface:DoubleDBIDHeapRemove the topmost element.- Specified by:
pollin interfaceDoubleDBIDHeap
-
size
public int size()
Description copied from interface:DoubleDBIDHeapCurrent size of heap.- Specified by:
sizein interfaceDoubleDBIDHeap- Returns:
- Heap size
-
isEmpty
public boolean isEmpty()
Description copied from interface:DoubleDBIDHeapTest if the heap is empty.- Specified by:
isEmptyin interfaceDoubleDBIDHeap- Returns:
- true when empty.
-
clear
public void clear()
Description copied from interface:DoubleDBIDHeapClear the heap.- Specified by:
clearin interfaceDoubleDBIDHeap
-
peekKey
public double peekKey()
Description copied from interface:DoubleDBIDHeapGet the topmost value (the heap is aDBIDRef, referencing the top element).- Specified by:
peekKeyin interfaceDoubleDBIDHeap- Returns:
- value at top
-
internalGetIndex
public int internalGetIndex()
Description copied from interface:DBIDRefInternal only: Get the internal index.NOT FOR PUBLIC USE - ELKI Optimization engine only.
- Specified by:
internalGetIndexin interfaceDBIDRef- Returns:
- Internal index
-
contains
public boolean contains(DBIDRef o)
Description copied from interface:DoubleDBIDHeapCheck if an object is already in the heap (slow scan).- Specified by:
containsin interfaceDoubleDBIDHeap- Parameters:
o- Other object- Returns:
trueif contained
-
unorderedIterator
public DoubleDBIDIter unorderedIterator()
Description copied from interface:DoubleDBIDHeapUnordered iterator over the heap.- Specified by:
unorderedIteratorin interfaceDoubleDBIDHeap- Returns:
- Iterator
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-