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 class
DoubleIntegerDBIDHeap.UnorderedIter
Iterate over all objects in the heap, not ordered.
-
Field Summary
Fields Modifier and Type Field Description private DoubleIntegerHeap
heap
The main heap.
-
Constructor Summary
Constructors Modifier Constructor Description protected
DoubleIntegerDBIDHeap(DoubleIntegerHeap heap)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear the heap.boolean
contains(DBIDRef o)
Check if an object is already in the heap (slow scan).double
insert(double distance, DBIDRef id)
Add a double-id pair to the heapdouble
insert(double distance, DBIDRef id, int max)
Add a double-id pair to the heap unless the heap grows beyond the given maximum size.int
internalGetIndex()
Internal only: Get the internal index.boolean
isEmpty()
Test if the heap is empty.double
peekKey()
Get the topmost value (the heap is aDBIDRef
, referencing the top element).void
poll()
Remove the topmost element.void
replaceTopElement(double distance, DBIDRef id)
Replace the top element.int
size()
Current size of heap.java.lang.String
toString()
DoubleDBIDIter
unorderedIterator()
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:DoubleDBIDHeap
Add a double-id pair to the heap- Specified by:
insert
in 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:DoubleDBIDHeap
Add 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:
insert
in 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:DoubleDBIDHeap
Remove the topmost element.- Specified by:
poll
in interfaceDoubleDBIDHeap
-
size
public int size()
Description copied from interface:DoubleDBIDHeap
Current size of heap.- Specified by:
size
in interfaceDoubleDBIDHeap
- Returns:
- Heap size
-
isEmpty
public boolean isEmpty()
Description copied from interface:DoubleDBIDHeap
Test if the heap is empty.- Specified by:
isEmpty
in interfaceDoubleDBIDHeap
- Returns:
- true when empty.
-
clear
public void clear()
Description copied from interface:DoubleDBIDHeap
Clear the heap.- Specified by:
clear
in interfaceDoubleDBIDHeap
-
peekKey
public double peekKey()
Description copied from interface:DoubleDBIDHeap
Get the topmost value (the heap is aDBIDRef
, referencing the top element).- Specified by:
peekKey
in interfaceDoubleDBIDHeap
- Returns:
- value at top
-
internalGetIndex
public int internalGetIndex()
Description copied from interface:DBIDRef
Internal only: Get the internal index.NOT FOR PUBLIC USE - ELKI Optimization engine only.
- Specified by:
internalGetIndex
in interfaceDBIDRef
- Returns:
- Internal index
-
contains
public boolean contains(DBIDRef o)
Description copied from interface:DoubleDBIDHeap
Check if an object is already in the heap (slow scan).- Specified by:
contains
in interfaceDoubleDBIDHeap
- Parameters:
o
- Other object- Returns:
true
if contained
-
unorderedIterator
public DoubleDBIDIter unorderedIterator()
Description copied from interface:DoubleDBIDHeap
Unordered iterator over the heap.- Specified by:
unorderedIterator
in interfaceDoubleDBIDHeap
- Returns:
- Iterator
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-