Package elki.database.ids.integer
Class DoubleIntegerDBIDKNNHeap
- java.lang.Object
-
- elki.database.ids.integer.DoubleIntegerDBIDHeap
-
- elki.database.ids.integer.DoubleIntegerDBIDKNNHeap
-
- All Implemented Interfaces:
DBIDRef,DoubleDBIDHeap,KNNHeap
class DoubleIntegerDBIDKNNHeap extends DoubleIntegerDBIDHeap implements KNNHeap
Class to efficiently manage a kNN heap.- Since:
- 0.6.0
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classDoubleIntegerDBIDKNNHeap.UnorderedIterIterate over all objects in the heap, not ordered.
-
Field Summary
Fields Modifier and Type Field Description private static intINITIAL_TIES_SIZEInitial size of ties array.private intkk for this heap.private doublekdistCurrent maximum value.private intnumtiesNumber of element in ties list.private int[]tiesList to track ties.
-
Constructor Summary
Constructors Modifier Constructor Description protectedDoubleIntegerDBIDKNNHeap(int k)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddToTies(int id)Ensure the ties array has capacity for at least one more element.voidclear()Clear the heap.booleancontains(DBIDRef o)Check if an object is already in the heap (slow scan).intgetK()Get the K parameter ("maxsize" internally).doublegetKNNDistance()Get the distance to the k nearest neighbor, or maxdist otherwise.doubleinsert(double distance, DBIDRef id)Add a double-id pair to the heapintinternalGetIndex()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.intsize()Current size of heap.DoubleIntegerDBIDKNNListtoKNNList()Serialize to aKNNList.DoubleIntegerDBIDKNNListtoKNNListSqrt()Serialize to aKNNList, but applying sqrt to every distance.java.lang.StringtoString()DoubleDBIDIterunorderedIterator()Unordered iterator over the heap.-
Methods inherited from class elki.database.ids.integer.DoubleIntegerDBIDHeap
insert, replaceTopElement
-
-
-
-
Field Detail
-
k
private final int k
k for this heap.
-
ties
private int[] ties
List to track ties.
-
numties
private int numties
Number of element in ties list.
-
kdist
private double kdist
Current maximum value.
-
INITIAL_TIES_SIZE
private static final int INITIAL_TIES_SIZE
Initial size of ties array.- See Also:
- Constant Field Values
-
-
Method Detail
-
getK
public int getK()
Description copied from interface:KNNHeapGet the K parameter ("maxsize" internally).
-
getKNNDistance
public double getKNNDistance()
Description copied from interface:KNNHeapGet the distance to the k nearest neighbor, or maxdist otherwise.- Specified by:
getKNNDistancein interfaceKNNHeap- Returns:
- Maximum distance
-
insert
public final double insert(double distance, DBIDRef id)Description copied from interface:DoubleDBIDHeapAdd a double-id pair to the heap- Specified by:
insertin interfaceDoubleDBIDHeap- Specified by:
insertin interfaceKNNHeap- Overrides:
insertin classDoubleIntegerDBIDHeap- Parameters:
distance- Key valueid- ID number- Returns:
- Value of to the element at the top of the heap
-
addToTies
private void addToTies(int id)
Ensure the ties array has capacity for at least one more element.- Parameters:
id- Id to add
-
poll
public void poll()
Description copied from interface:DoubleDBIDHeapRemove the topmost element.- Specified by:
pollin interfaceDoubleDBIDHeap- Overrides:
pollin classDoubleIntegerDBIDHeap
-
size
public int size()
Description copied from interface:DoubleDBIDHeapCurrent size of heap.- Specified by:
sizein interfaceDoubleDBIDHeap- Overrides:
sizein classDoubleIntegerDBIDHeap- Returns:
- Heap size
-
isEmpty
public boolean isEmpty()
Description copied from interface:DoubleDBIDHeapTest if the heap is empty.- Specified by:
isEmptyin interfaceDoubleDBIDHeap- Overrides:
isEmptyin classDoubleIntegerDBIDHeap- Returns:
- true when empty.
-
clear
public void clear()
Description copied from interface:DoubleDBIDHeapClear the heap.- Specified by:
clearin interfaceDoubleDBIDHeap- Overrides:
clearin classDoubleIntegerDBIDHeap
-
toKNNList
public DoubleIntegerDBIDKNNList toKNNList()
Description copied from interface:KNNHeapSerialize to aKNNList. This empties the heap!
-
toKNNListSqrt
public DoubleIntegerDBIDKNNList toKNNListSqrt()
Description copied from interface:KNNHeapSerialize to aKNNList, but applying sqrt to every distance. This empties the heap!- Specified by:
toKNNListSqrtin interfaceKNNHeap- Returns:
- KNNList with the heaps contents.
-
peekKey
public double peekKey()
Description copied from interface:DoubleDBIDHeapGet the topmost value (the heap is aDBIDRef, referencing the top element).- Specified by:
peekKeyin interfaceDoubleDBIDHeap- Overrides:
peekKeyin classDoubleIntegerDBIDHeap- 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- Overrides:
internalGetIndexin classDoubleIntegerDBIDHeap- 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- Overrides:
containsin classDoubleIntegerDBIDHeap- Parameters:
o- Other object- Returns:
trueif contained
-
unorderedIterator
public DoubleDBIDIter unorderedIterator()
Description copied from interface:DoubleDBIDHeapUnordered iterator over the heap.- Specified by:
unorderedIteratorin interfaceDoubleDBIDHeap- Overrides:
unorderedIteratorin classDoubleIntegerDBIDHeap- Returns:
- Iterator
-
toString
public java.lang.String toString()
- Overrides:
toStringin classDoubleIntegerDBIDHeap
-
-