summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/database/ids
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/database/ids')
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/ArrayDBIDs.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/ArrayModifiableDBIDs.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/ArrayStaticDBIDs.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DBID.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DBIDArrayIter.java14
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DBIDArrayMIter.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DBIDFactory.java76
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DBIDIter.java7
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DBIDMIter.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DBIDPair.java17
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DBIDRange.java8
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DBIDRef.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java210
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DBIDVar.java28
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DBIDs.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DoubleDBIDList.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/distance/DistanceDBIDList.java)30
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DoubleDBIDListIter.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/distance/DistanceDBIDListIter.java)41
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/DoubleDBIDPair.java35
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/EmptyDBIDs.java14
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/HashSetDBIDs.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/HashSetModifiableDBIDs.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/KNNHeap.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/distance/KNNHeap.java)39
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/KNNList.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/distance/KNNList.java)16
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/ModifiableDBIDs.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/ModifiableDoubleDBIDList.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/distance/ModifiableDistanceDBIDList.java)27
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/SetDBIDs.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/StaticDBIDs.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/distance/DistanceDBIDPair.java53
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDListIter.java60
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDPair.java54
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDPairList.java217
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceKNNHeap.java101
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceKNNList.java55
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/distance/ModifiableDoubleDistanceDBIDList.java68
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/distance/package-info.java26
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/AbstractKNNHeap.java93
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/DBIDIterAdapter.java82
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/DistanceDBIDPairKNNHeap.java106
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/DistanceDBIDPairKNNList.java211
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceDBIDPairKNNHeap.java218
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceDBIDPairKNNList.java257
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceDBIDPairKNNListHeap.java289
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/GenericDistanceDBIDList.java206
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/KNNSubList.java72
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/MaskedDBIDs.java10
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/MergedDBIDs.java83
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/UnmodifiableArrayDBIDs.java14
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/UnmodifiableDBIDs.java5
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/generic/package-info.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/AbstractIntegerDBIDFactory.java74
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/ArrayModifiableIntegerDBIDs.java28
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/ArrayStaticIntegerDBIDs.java30
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/DistanceIntegerDBIDPair.java101
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDPair.java110
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDPairKNNListHeap.java339
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerArrayQuickSort.java181
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDKNNHeap.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDKNNHeap.java)111
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDKNNList.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDKNNList.java)30
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDList.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDList.java)96
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDListIter.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDListIter.java)12
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDListKNNHeap.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDSortedKNNList.java)45
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDPair.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDoubleDBIDPair.java)19
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDPairKNNListHeap.java286
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDPairList.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDPairList.java)117
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerArrayDBIDs.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerArrayStaticDBIDs.java4
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBID.java24
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayIter.java4
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayMIter.java4
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayQuickSort.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDIter.java4
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDKNNList.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDList.java)18
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDKNNSubList.java (renamed from src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceKNNSubList.java)77
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDMIter.java4
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDPair.java94
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDRange.java14
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDRef.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDVar.java78
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDs.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/ReusingDBIDFactory.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/SimpleDBIDFactory.java14
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/TrivialDBIDFactory.java22
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/TroveHashSetModifiableDBIDs.java8
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/UnmodifiableIntegerArrayDBIDs.java17
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/UnmodifiableIntegerDBIDs.java6
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/integer/package-info.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/ids/package-info.java12
87 files changed, 1124 insertions, 3741 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/ArrayDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/ArrayDBIDs.java
index 5839a2e0..3cca1242 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/ArrayDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/ArrayDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/ArrayModifiableDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/ArrayModifiableDBIDs.java
index 3db40630..0554a0e2 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/ArrayModifiableDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/ArrayModifiableDBIDs.java
@@ -6,7 +6,7 @@ import java.util.Comparator;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/ArrayStaticDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/ArrayStaticDBIDs.java
index 47cf295f..6328f375 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/ArrayStaticDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/ArrayStaticDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DBID.java b/src/de/lmu/ifi/dbs/elki/database/ids/DBID.java
index a773ee27..c46b13bd 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DBID.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DBID.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDArrayIter.java b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDArrayIter.java
index ef1132b3..c5cf171a 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDArrayIter.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDArrayIter.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -30,5 +30,15 @@ import de.lmu.ifi.dbs.elki.utilities.datastructures.iterator.ArrayIter;
* @author Erich Schubert
*/
public interface DBIDArrayIter extends DBIDIter, ArrayIter {
- // Nothing added - see {@link ArrayIter}!
+ @Override
+ DBIDArrayIter advance();
+
+ @Override
+ DBIDArrayIter advance(int count);
+
+ @Override
+ DBIDArrayIter retract();
+
+ @Override
+ DBIDArrayIter seek(int off);
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDArrayMIter.java b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDArrayMIter.java
index 1aaefc8e..9700de1b 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDArrayMIter.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDArrayMIter.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDFactory.java b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDFactory.java
index 1b269eea..58cf5791 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDFactory.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDFactory.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,15 +23,9 @@ package de.lmu.ifi.dbs.elki.database.ids;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNHeap;
-import de.lmu.ifi.dbs.elki.database.ids.distance.KNNHeap;
-import de.lmu.ifi.dbs.elki.database.ids.distance.KNNList;
import de.lmu.ifi.dbs.elki.database.ids.integer.TrivialDBIDFactory;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
-import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
-import de.lmu.ifi.dbs.elki.persistent.FixedSizeByteBufferSerializer;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteBufferSerializer;
+import de.lmu.ifi.dbs.elki.utilities.io.FixedSizeByteBufferSerializer;
/**
* Factory interface for generating DBIDs. See {@link #FACTORY} for the static
@@ -106,6 +100,15 @@ public interface DBIDFactory {
DBIDRange generateStaticDBIDRange(int size);
/**
+ * Generate a static DBID range.
+ *
+ * @param begin Range begin
+ * @param size Requested size
+ * @return DBID range
+ */
+ DBIDRange generateStaticDBIDRange(int begin, int size);
+
+ /**
* Deallocate a static DBID range.
*
* @param range Range to deallocate
@@ -132,25 +135,6 @@ public interface DBIDFactory {
DoubleDBIDPair newPair(double val, DBIDRef id);
/**
- * Make a new distance-DBID pair.
- *
- * @param val Distance value
- * @param id Object ID
- * @param <D> Distance type
- * @return New pair
- */
- <D extends Distance<D>> DistanceDBIDPair<D> newDistancePair(D val, DBIDRef id);
-
- /**
- * Make a new distance-DBID pair.
- *
- * @param val Distance value
- * @param id Object ID
- * @return New pair
- */
- DoubleDistanceDBIDPair newDistancePair(double val, DBIDRef id);
-
- /**
* Make a new (modifiable) array of DBIDs.
*
* @return New array
@@ -197,33 +181,20 @@ public interface DBIDFactory {
HashSetModifiableDBIDs newHashSet(DBIDs existing);
/**
- * Create an appropriate heap for the distance function.
- *
- * This will use a double heap if appropriate.
+ * Create an heap for kNN search.
*
- * @param factory distance prototype
* @param k K value
- * @param <D> distance type
- * @return New heap of size k, appropriate for this distance type.
+ * @return New heap of size k.
*/
- <D extends Distance<D>> KNNHeap<D> newHeap(D factory, int k);
+ KNNHeap newHeap(int k);
/**
* Build a new heap from a given list.
*
* @param exist Existing result
- * @param <D> Distance type
* @return New heap
*/
- <D extends Distance<D>> KNNHeap<D> newHeap(KNNList<D> exist);
-
- /**
- * Create an appropriate heap for double distances.
- *
- * @param k K value
- * @return New heap of size k, appropriate for this distance type.
- */
- DoubleDistanceKNNHeap newDoubleDistanceHeap(int k);
+ KNNHeap newHeap(KNNList exist);
/**
* Get a serializer for DBIDs.
@@ -278,4 +249,19 @@ public interface DBIDFactory {
* @return Invalid value
*/
DBIDRef invalid();
+
+ /**
+ * Create a modifiable list to store distance-DBID pairs.
+ *
+ * @param size initial size estimate
+ * @return New list of given initial size
+ */
+ ModifiableDoubleDBIDList newDistanceDBIDList(int size);
+
+ /**
+ * Create a modifiable list to store distance-DBID pairs.
+ *
+ * @return New list
+ */
+ ModifiableDoubleDBIDList newDistanceDBIDList();
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDIter.java b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDIter.java
index f051d51c..0c1bedba 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDIter.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDIter.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -54,9 +54,10 @@ import de.lmu.ifi.dbs.elki.utilities.datastructures.iterator.Iter;
* </ul>
*
* @author Erich Schubert
- *
+ *
* @apiviz.landmark
*/
public interface DBIDIter extends DBIDRef, Iter {
- // Empty - use as DBIDRef or Iter
+ @Override
+ DBIDIter advance();
} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDMIter.java b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDMIter.java
index 0fbed7e0..8778a5a3 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDMIter.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDMIter.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDPair.java b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDPair.java
index bdbbe2da..f8bcfb88 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDPair.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDPair.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,8 +23,6 @@ package de.lmu.ifi.dbs.elki.database.ids;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.utilities.pairs.PairInterface;
-
/**
* Immutable pair of two DBIDs. This can be stored more efficiently than when
* using {@link de.lmu.ifi.dbs.elki.utilities.pairs.Pair}
@@ -33,21 +31,24 @@ import de.lmu.ifi.dbs.elki.utilities.pairs.PairInterface;
*
* @apiviz.composedOf de.lmu.ifi.dbs.elki.database.ids.DBID
*/
-// TODO: implement DBIDs?
-public interface DBIDPair extends PairInterface<DBID, DBID> {
+public interface DBIDPair extends DBIDs {
/**
- * Getter for first
+ * Getter for first.
*
* @return first element in pair
+ * @deprecated This method can be expensive. The use of a {@link DBIDVar} is
+ * recommended when many such accesses are needed.
*/
- @Override
+ @Deprecated
public DBID getFirst();
/**
* Getter for second element in pair
*
* @return second element in pair
+ * @deprecated This method can be expensive. The use of a {@link DBIDVar} is
+ * recommended when many such accesses are needed.
*/
- @Override
+ @Deprecated
public DBID getSecond();
} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDRange.java b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDRange.java
index 588cfe6a..1bd2d0d1 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDRange.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDRange.java
@@ -1,12 +1,10 @@
package de.lmu.ifi.dbs.elki.database.ids;
-import de.lmu.ifi.dbs.elki.database.datastore.DataStoreIDMap;
-
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -25,6 +23,8 @@ import de.lmu.ifi.dbs.elki.database.datastore.DataStoreIDMap;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+import de.lmu.ifi.dbs.elki.database.datastore.DataStoreIDMap;
+
/**
* Static DBID range.
*
@@ -35,7 +35,7 @@ public interface DBIDRange extends ArrayStaticDBIDs, DataStoreIDMap {
* Get offset in the array for a particular DBID.
*
* Should satisfy {@code range.get(getOffset(id)) == id} and
- * {@code range.getOffset(range.get(idx)) == idx}.
+ * {@code range.getOffset(range.get(idx)) == idx}.
*
* @param dbid ID to compute index for
* @return index
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDRef.java b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDRef.java
index 77cc621e..8d7ee6b3 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDRef.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDRef.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java
index c60e63ae..9c39fc77 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDUtil.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -25,24 +25,19 @@ package de.lmu.ifi.dbs.elki.database.ids;
import java.util.Random;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNHeap;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNList;
-import de.lmu.ifi.dbs.elki.database.ids.distance.KNNHeap;
-import de.lmu.ifi.dbs.elki.database.ids.distance.KNNList;
-import de.lmu.ifi.dbs.elki.database.ids.generic.DoubleDistanceKNNSubList;
import de.lmu.ifi.dbs.elki.database.ids.generic.KNNSubList;
import de.lmu.ifi.dbs.elki.database.ids.generic.UnmodifiableArrayDBIDs;
import de.lmu.ifi.dbs.elki.database.ids.generic.UnmodifiableDBIDs;
import de.lmu.ifi.dbs.elki.database.ids.integer.IntegerArrayDBIDs;
+import de.lmu.ifi.dbs.elki.database.ids.integer.IntegerDBIDKNNList;
+import de.lmu.ifi.dbs.elki.database.ids.integer.IntegerDBIDKNNSubList;
import de.lmu.ifi.dbs.elki.database.ids.integer.IntegerDBIDs;
import de.lmu.ifi.dbs.elki.database.ids.integer.UnmodifiableIntegerArrayDBIDs;
import de.lmu.ifi.dbs.elki.database.ids.integer.UnmodifiableIntegerDBIDs;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
-import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
-import de.lmu.ifi.dbs.elki.utilities.RandomFactory;
-import de.lmu.ifi.dbs.elki.utilities.UnsafeRandom;
+import de.lmu.ifi.dbs.elki.math.random.FastNonThreadsafeRandom;
+import de.lmu.ifi.dbs.elki.math.random.RandomFactory;
+import de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteBufferSerializer;
/**
* DBID Utility functions.
@@ -51,9 +46,8 @@ import de.lmu.ifi.dbs.elki.utilities.UnsafeRandom;
*
* @apiviz.landmark
*
- * @apiviz.has DBID
* @apiviz.has DBIDs
- * @apiviz.uses DBIDRef
+ * @apiviz.has DBIDRef
* @apiviz.composedOf DBIDFactory
*/
public final class DBIDUtil {
@@ -131,7 +125,7 @@ public final class DBIDUtil {
* @return DBID
*/
public static DBID deref(DBIDRef ref) {
- if (ref instanceof DBID) {
+ if(ref instanceof DBID) {
return (DBID) ref;
}
return importInteger(ref.internalGetIndex());
@@ -154,12 +148,12 @@ public final class DBIDUtil {
* @return String representation
*/
public static String toString(DBIDs ids) {
- if (ids instanceof DBID) {
+ if(ids instanceof DBID) {
return DBIDFactory.FACTORY.toString((DBID) ids);
}
StringBuilder buf = new StringBuilder();
- for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
- if (buf.length() > 0) {
+ for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
+ if(buf.length() > 0) {
buf.append(", ");
}
buf.append(DBIDFactory.FACTORY.toString(iter));
@@ -308,12 +302,12 @@ public final class DBIDUtil {
*/
// TODO: optimize better?
public static ModifiableDBIDs intersection(DBIDs first, DBIDs second) {
- if (first.size() > second.size()) {
+ if(first.size() > second.size()) {
return intersection(second, first);
}
ModifiableDBIDs inter = newHashSet(first.size());
- for (DBIDIter it = first.iter(); it.valid(); it.advance()) {
- if (second.contains(it)) {
+ for(DBIDIter it = first.iter(); it.valid(); it.advance()) {
+ if(second.contains(it)) {
inter.add(it);
}
}
@@ -329,20 +323,22 @@ public final class DBIDUtil {
*/
public static int intersectionSize(DBIDs first, DBIDs second) {
// If exactly one is a Set, use it as second parameter.
- if (second instanceof SetDBIDs) {
- if (!(first instanceof SetDBIDs)) {
+ if(second instanceof SetDBIDs) {
+ if(!(first instanceof SetDBIDs)) {
return internalIntersectionSize(first, second);
}
- } else {
- if (first instanceof SetDBIDs) {
+ }
+ else {
+ if(first instanceof SetDBIDs) {
return internalIntersectionSize(second, first);
}
}
// Both are the same type: both set or both non set.
// Smaller goes first.
- if (first.size() <= second.size()) {
+ if(first.size() <= second.size()) {
return internalIntersectionSize(first, second);
- } else {
+ }
+ else {
return internalIntersectionSize(second, first);
}
}
@@ -356,8 +352,8 @@ public final class DBIDUtil {
*/
private static int internalIntersectionSize(DBIDs first, DBIDs second) {
int c = 0;
- for (DBIDIter it = first.iter(); it.valid(); it.advance()) {
- if (second.contains(it)) {
+ for(DBIDIter it = first.iter(); it.valid(); it.advance()) {
+ if(second.contains(it)) {
c++;
}
}
@@ -375,7 +371,7 @@ public final class DBIDUtil {
*/
// TODO: optimize?
public static void symmetricIntersection(DBIDs first, DBIDs second, HashSetModifiableDBIDs firstonly, HashSetModifiableDBIDs intersection, HashSetModifiableDBIDs secondonly) {
- if (first.size() > second.size()) {
+ if(first.size() > second.size()) {
symmetricIntersection(second, first, secondonly, intersection, firstonly);
return;
}
@@ -384,11 +380,12 @@ public final class DBIDUtil {
assert (secondonly.size() == 0) : "OUTPUT set should be empty!";
// Initialize with second
secondonly.addDBIDs(second);
- for (DBIDIter it = first.iter(); it.valid(); it.advance()) {
+ for(DBIDIter it = first.iter(); it.valid(); it.advance()) {
// Try to remove
- if (secondonly.remove(it)) {
+ if(secondonly.remove(it)) {
intersection.add(it);
- } else {
+ }
+ else {
firstonly.add(it);
}
}
@@ -428,16 +425,16 @@ public final class DBIDUtil {
* @return Unmodifiable collection
*/
public static StaticDBIDs makeUnmodifiable(DBIDs existing) {
- if (existing instanceof StaticDBIDs) {
+ if(existing instanceof StaticDBIDs) {
return (StaticDBIDs) existing;
}
- if (existing instanceof IntegerArrayDBIDs) {
+ if(existing instanceof IntegerArrayDBIDs) {
return new UnmodifiableIntegerArrayDBIDs((IntegerArrayDBIDs) existing);
}
- if (existing instanceof IntegerDBIDs) {
+ if(existing instanceof IntegerDBIDs) {
return new UnmodifiableIntegerDBIDs((IntegerDBIDs) existing);
}
- if (existing instanceof ArrayDBIDs) {
+ if(existing instanceof ArrayDBIDs) {
return new UnmodifiableArrayDBIDs((ArrayDBIDs) existing);
}
return new UnmodifiableDBIDs(existing);
@@ -450,9 +447,10 @@ public final class DBIDUtil {
* @return Array DBIDs.
*/
public static ArrayDBIDs ensureArray(DBIDs ids) {
- if (ids instanceof ArrayDBIDs) {
+ if(ids instanceof ArrayDBIDs) {
return (ArrayDBIDs) ids;
- } else {
+ }
+ else {
return newArray(ids);
}
}
@@ -464,9 +462,10 @@ public final class DBIDUtil {
* @return Set DBIDs.
*/
public static SetDBIDs ensureSet(DBIDs ids) {
- if (ids instanceof SetDBIDs) {
+ if(ids instanceof SetDBIDs) {
return (SetDBIDs) ids;
- } else {
+ }
+ else {
return newHashSet(ids);
}
}
@@ -478,13 +477,14 @@ public final class DBIDUtil {
* @return Modifiable DBIDs.
*/
public static ModifiableDBIDs ensureModifiable(DBIDs ids) {
- if (ids instanceof ModifiableDBIDs) {
+ if(ids instanceof ModifiableDBIDs) {
return (ModifiableDBIDs) ids;
- } else {
- if (ids instanceof ArrayDBIDs) {
+ }
+ else {
+ if(ids instanceof ArrayDBIDs) {
return newArray(ids);
}
- if (ids instanceof HashSetDBIDs) {
+ if(ids instanceof HashSetDBIDs) {
return newHashSet(ids);
}
return newArray(ids);
@@ -515,59 +515,24 @@ public final class DBIDUtil {
}
/**
- * Make a DistanceDBIDPair.
- *
- * @param dist Distance value
- * @param id ID
- * @return new pair
- */
- public static <D extends Distance<D>> DistanceDBIDPair<D> newDistancePair(D dist, DBIDRef id) {
- return DBIDFactory.FACTORY.newDistancePair(dist, id);
- }
-
- /**
- * Make a DoubleDistanceDBIDPair.
- *
- * @param dist Distance value
- * @param id ID
- * @return new pair
- */
- public static DoubleDistanceDBIDPair newDistancePair(double dist, DBIDRef id) {
- return DBIDFactory.FACTORY.newDistancePair(dist, id);
- }
-
- /**
* Create an appropriate heap for the distance type.
*
* This will use a double heap if appropriate.
*
- * @param distancetype distance prototype
- * @param k K value
- * @param <D> distance type
- * @return New heap of size k, appropriate for this distance type.
- */
- public static <D extends Distance<D>> KNNHeap<D> newHeap(D distancetype, int k) {
- return DBIDFactory.FACTORY.newHeap(distancetype, k);
- }
-
- /**
- * Create an appropriate heap for double distances.
- *
* @param k K value
* @return New heap of size k, appropriate for this distance type.
*/
- public static DoubleDistanceKNNHeap newDoubleDistanceHeap(int k) {
- return DBIDFactory.FACTORY.newDoubleDistanceHeap(k);
+ public static KNNHeap newHeap(int k) {
+ return DBIDFactory.FACTORY.newHeap(k);
}
/**
* Build a new heap from a given list.
*
* @param exist Existing result
- * @param <D> Distance type
* @return New heap
*/
- public static <D extends Distance<D>> KNNHeap<D> newHeap(KNNList<D> exist) {
+ public static KNNHeap newHeap(KNNList exist) {
return DBIDFactory.FACTORY.newHeap(exist);
}
@@ -601,7 +566,7 @@ public final class DBIDUtil {
* @param limit Shuffling limit.
*/
public static void randomShuffle(ArrayModifiableDBIDs ids, Random random, final int limit) {
- for (int i = 1; i < limit; i++) {
+ for(int i = 1; i < limit; i++) {
ids.swap(i - 1, i + random.nextInt(limit - i));
}
}
@@ -627,9 +592,10 @@ public final class DBIDUtil {
* @return new DBIDs
*/
public static ModifiableDBIDs randomSample(DBIDs source, int k, Long seed) {
- if (seed != null) {
+ if(seed != null) {
return randomSample(source, k, new Random(seed.longValue()));
- } else {
+ }
+ else {
return randomSample(source, k, new Random());
}
}
@@ -655,29 +621,31 @@ public final class DBIDUtil {
* @return new DBIDs
*/
public static ModifiableDBIDs randomSample(DBIDs source, int k, Random random) {
- if (k < 0 || k > source.size()) {
+ if(k < 0 || k > source.size()) {
throw new IllegalArgumentException("Illegal value for size of random sample: " + k + " > " + source.size() + " or < 0");
}
- if (random == null) {
- random = new UnsafeRandom(); // Fast, and we're single-threaded here anyway.
+ if(random == null) {
+ // Fast, and we're single-threaded here anyway.
+ random = new FastNonThreadsafeRandom();
}
-
+
// TODO: better balancing for different sizes
// Two methods: constructive vs. destructive
- if (k < source.size() >> 1) {
+ if(k < source.size() >> 1) {
ArrayDBIDs aids = DBIDUtil.ensureArray(source);
DBIDArrayIter iter = aids.iter();
HashSetModifiableDBIDs sample = DBIDUtil.newHashSet(k);
- while (sample.size() < k) {
+ while(sample.size() < k) {
iter.seek(random.nextInt(aids.size()));
sample.add(iter);
}
return sample;
- } else {
+ }
+ else {
ArrayModifiableDBIDs sample = DBIDUtil.newArray(source);
randomShuffle(sample, random, k);
// Delete trailing elements
- for (int i = sample.size() - 1; i > k; i--) {
+ for(int i = sample.size() - 1; i > k; i--) {
sample.remove(i);
}
return sample;
@@ -703,19 +671,20 @@ public final class DBIDUtil {
* @param random Random generator
*/
public static ArrayDBIDs[] randomSplit(DBIDs oids, int p, Random random) {
- if (random == null) {
- random = new UnsafeRandom(); // Fast, and we're single-threaded here anyway.
+ if(random == null) {
+ // Fast, and we're single-threaded here anyway.
+ random = new FastNonThreadsafeRandom();
}
ArrayModifiableDBIDs ids = newArray(oids);
final int size = ids.size();
ArrayDBIDs[] split = new ArrayDBIDs[p];
// Shuffle
- for (int i = 1; i < size; i++) {
+ for(int i = 1; i < size; i++) {
ids.swap(i - 1, i + random.nextInt(size - i));
}
final int minsize = size / p; // Floor.
final int extra = size % p; // Remainder
- for (int beg = 0, part = 0; part < p; part++) {
+ for(int beg = 0, part = 0; part < p; part++) {
// First partitions are smaller, last partitions are larger.
final int psize = minsize + ((part < extra) ? 1 : 0);
split[part] = ids.slice(beg, beg + psize);
@@ -729,17 +698,48 @@ public final class DBIDUtil {
*
* @param list Existing list
* @param k k
- * @param <D> distance type
* @return Subset
*/
- @SuppressWarnings("unchecked")
- public static <D extends Distance<D>> KNNList<D> subList(KNNList<D> list, int k) {
- if (k >= list.size()) {
+ public static KNNList subList(KNNList list, int k) {
+ if(k >= list.size()) {
return list;
}
- if (list instanceof DoubleDistanceKNNList) {
- return (KNNList<D>) new DoubleDistanceKNNSubList((DoubleDistanceKNNList) list, k);
+ if(list instanceof IntegerDBIDKNNList) {
+ return new IntegerDBIDKNNSubList((IntegerDBIDKNNList) list, k);
+ }
+ return new KNNSubList(list, k);
+ }
+
+ /**
+ * Create a modifiable list to store distance-DBID pairs.
+ *
+ * @param size Estimated upper list size
+ * @return Empty list
+ */
+ public static ModifiableDoubleDBIDList newDistanceDBIDList(int size) {
+ return DBIDFactory.FACTORY.newDistanceDBIDList(size);
+ }
+
+ /**
+ * Create a modifiable list to store distance-DBID pairs.
+ *
+ * @return Empty list
+ */
+ public static ModifiableDoubleDBIDList newDistanceDBIDList() {
+ return DBIDFactory.FACTORY.newDistanceDBIDList();
+ }
+
+ /**
+ * Assert that the presented ids constitute a continuous {@link DBIDRange}.
+ *
+ * @param ids ID range.
+ * @return DBID range.
+ * @throws AbortException
+ */
+ public static DBIDRange assertRange(DBIDs ids) {
+ if(!(ids instanceof DBIDRange)) {
+ throw new AbortException("This class may currently only be used with static databases and DBID ranges.");
}
- return new KNNSubList<>(list, k);
+ return (DBIDRange) ids;
}
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDVar.java b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDVar.java
index 94480fe9..bdc7b76a 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDVar.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDVar.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -39,4 +39,30 @@ public interface DBIDVar extends DBIDRef, ArrayDBIDs, SetDBIDs {
* @param ref Reference
*/
void set(DBIDRef ref);
+
+ /**
+ * Clear the contents.
+ */
+ void unset();
+
+ /**
+ * Test if the variable is well-defined.
+ *
+ * @return {@code true} when assigned.
+ */
+ boolean isSet();
+
+ /**
+ * Assign the first pair member to this variable.
+ *
+ * @param pair Pair
+ */
+ void setFirst(DBIDPair pair);
+
+ /**
+ * Assign the second pair member to this variable.
+ *
+ * @param pair Pair
+ */
+ void setSecond(DBIDPair pair);
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDs.java
index 2bf2b28d..5aecff02 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DistanceDBIDList.java b/src/de/lmu/ifi/dbs/elki/database/ids/DoubleDBIDList.java
index 360dda12..939a0fe7 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DistanceDBIDList.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DoubleDBIDList.java
@@ -1,10 +1,10 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
+package de.lmu.ifi.dbs.elki.database.ids;
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,19 +23,17 @@ package de.lmu.ifi.dbs.elki.database.ids.distance;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.database.ids.DBIDs;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
/**
- * Collection of objects and their distances.
+ * Collection of double values associated with objects.
*
* To iterate over the results, use the following code:
*
* <pre>
* {@code
- * for (DistanceDBIDResultIter<D> iter = result.iter(); iter.valid(); iter.advance()) {
- * // You can get the distance via: iter.getDistance();
- * // Or use iter just like any other DBIDRef
+ * for (DoubleDBIDListIter iter = result.iter(); iter.valid(); iter.advance()) {
+ * // You can get the distance via: iter.doubleValue();
+ * // And use iter just like any other DBIDRef
* }
* }
* </pre>
@@ -45,7 +43,7 @@ import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
*
* <pre>
* {@code
- * for (DBIDIter<D> iter = result.iter(); iter.valid(); iter.advance()) {
+ * for (DBIDIter iter = result.iter(); iter.valid(); iter.advance()) {
* // Use iter just like any other DBIDRef
* }
* }
@@ -55,12 +53,10 @@ import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
*
* @apiviz.landmark
*
- * @apiviz.composedOf DistanceDBIDPair
- * @apiviz.has DistanceDBIDListIter
- *
- * @param <D> Distance type
+ * @apiviz.composedOf DoubleDBIDPair
+ * @apiviz.has DoubleDBIDListIter
*/
-public interface DistanceDBIDList<D extends Distance<D>> extends DBIDs {
+public interface DoubleDBIDList extends DBIDs {
/**
* Size of list.
*
@@ -70,12 +66,12 @@ public interface DistanceDBIDList<D extends Distance<D>> extends DBIDs {
int size();
/**
- * Access a single pair.
+ * Materialize a single pair.
*
* @param off Offset
* @return Pair
*/
- DistanceDBIDPair<D> get(int off);
+ DoubleDBIDPair get(int off);
/**
* Get an iterator
@@ -83,5 +79,5 @@ public interface DistanceDBIDList<D extends Distance<D>> extends DBIDs {
* @return New iterator
*/
@Override
- DistanceDBIDListIter<D> iter();
+ DoubleDBIDListIter iter();
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DistanceDBIDListIter.java b/src/de/lmu/ifi/dbs/elki/database/ids/DoubleDBIDListIter.java
index 914f3676..d5b0e4f7 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DistanceDBIDListIter.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DoubleDBIDListIter.java
@@ -1,10 +1,11 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
+package de.lmu.ifi.dbs.elki.database.ids;
+
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,11 +24,8 @@ package de.lmu.ifi.dbs.elki.database.ids.distance;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
-
/**
- * Iterator over distance-based query results.
+ * Iterator over double-DBID pairs results.
*
* There is no getter for the DBID, as this implements
* {@link de.lmu.ifi.dbs.elki.database.ids.DBIDRef}.
@@ -36,20 +34,37 @@ import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
*
* @apiviz.landmark
*
- * @apiviz.has DistanceDBIDPair - - iterator for
+ * @apiviz.has DoubleDBIDPair
*/
-public interface DistanceDBIDListIter<D extends Distance<D>> extends DBIDArrayIter {
+public interface DoubleDBIDListIter extends DBIDArrayIter {
/**
- * Get the distance
+ * Get the double value
*
- * @return distance
+ * @return double value
*/
- public D getDistance();
+ public double doubleValue();
/**
- * Get an object pair.
+ * Materialize an object pair.
+ *
+ * Note: currently, this will create a <em>new object</em>. In order to avoid
+ * the garbage collection overhead, it is preferable to use
+ * {@code #doubleValue()} and exploit that the iterator itself is a
+ * {@code DBIDRef} reference.
*
* @return object pair
*/
- public DistanceDBIDPair<D> getDistancePair();
+ public DoubleDBIDPair getPair();
+
+ @Override
+ DoubleDBIDListIter advance();
+
+ @Override
+ DoubleDBIDListIter advance(int count);
+
+ @Override
+ DoubleDBIDListIter retract();
+
+ @Override
+ DoubleDBIDListIter seek(int off);
} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/DoubleDBIDPair.java b/src/de/lmu/ifi/dbs/elki/database/ids/DoubleDBIDPair.java
index 970092b0..9459dbf6 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/DoubleDBIDPair.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/DoubleDBIDPair.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,42 +23,19 @@ package de.lmu.ifi.dbs.elki.database.ids;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.utilities.pairs.PairInterface;
-
/**
- * Pair of a double value and a DBID
+ * Pair of a double value and a DBID.
+ *
+ * Note: this interface implements {@link DBIDRef}, i.e. it can be used as DBID
+ * object reference.
*
* @author Erich Schubert
*/
-public interface DoubleDBIDPair extends PairInterface<Double, DBID>, DBIDRef, Comparable<DoubleDBIDPair> {
+public interface DoubleDBIDPair extends DBIDRef, Comparable<DoubleDBIDPair> {
/**
* Get the double value of the pair.
*
* @return Double
*/
public double doubleValue();
-
- /**
- * Get the first object - note: this may cause autoboxing, use pair.first for
- * native pairs!
- *
- * @deprecated Avoid autoboxing. Use {@link #doubleValue}!
- *
- * @return First object
- */
- @Override
- @Deprecated
- public Double getFirst();
-
- /**
- * Get the second object - note: this may cause autoboxing, use pair.second
- * for native pairs!
- *
- * @deprecated Avoid autoboxing! Use {@link DBIDRef} interface!
- *
- * @return Second object
- */
- @Override
- @Deprecated
- public DBID getSecond();
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/EmptyDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/EmptyDBIDs.java
index 0081fd44..3fb539df 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/EmptyDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/EmptyDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -99,8 +99,9 @@ public class EmptyDBIDs implements ArrayStaticDBIDs, SetDBIDs {
}
@Override
- public void advance() {
+ public EmptyDBIDIterator advance() {
assert (false) : "Misplaced call to advance()";
+ return this;
}
@Override
@@ -122,18 +123,21 @@ public class EmptyDBIDs implements ArrayStaticDBIDs, SetDBIDs {
}
@Override
- public void advance(int count) {
+ public EmptyDBIDIterator advance(int count) {
assert (count != 0) : "Misplaced call to advance()";
+ return this;
}
@Override
- public void retract() {
+ public EmptyDBIDIterator retract() {
assert (false) : "Misplaced call to retract()";
+ return this;
}
@Override
- public void seek(int off) {
+ public EmptyDBIDIterator seek(int off) {
// Ignore
+ return this;
}
@Override
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/HashSetDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/HashSetDBIDs.java
index cabe9898..6fcb40cc 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/HashSetDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/HashSetDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/HashSetModifiableDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/HashSetModifiableDBIDs.java
index 6a57f5f0..90574599 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/HashSetModifiableDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/HashSetModifiableDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/KNNHeap.java b/src/de/lmu/ifi/dbs/elki/database/ids/KNNHeap.java
index 5e94de47..1169caf6 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/KNNHeap.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/KNNHeap.java
@@ -1,10 +1,10 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
+package de.lmu.ifi.dbs.elki.database.ids;
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,30 +23,27 @@ package de.lmu.ifi.dbs.elki.database.ids.distance;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
/**
* Interface for kNN heaps.
*
- * To instantiate, use: {@link de.lmu.ifi.dbs.elki.database.ids.DBIDUtil#newHeap}!
+ * To instantiate, use:
+ * {@link de.lmu.ifi.dbs.elki.database.ids.DBIDUtil#newHeap}!
*
* @author Erich Schubert
*
* @apiviz.landmark
*
* @apiviz.uses KNNList - - «serializes to»
- * @apiviz.composedOf DistanceDBIDPair
- *
- * @param <D> Distance function
+ * @apiviz.composedOf DoubleDBIDPair
*/
-public interface KNNHeap<D extends Distance<D>> {
+public interface KNNHeap {
/**
* Serialize to a {@link KNNList}. This empties the heap!
*
* @return KNNList with the heaps contents.
*/
- KNNList<D> toKNNList();
+ KNNList toKNNList();
/**
* Get the K parameter ("maxsize" internally).
@@ -60,7 +57,7 @@ public interface KNNHeap<D extends Distance<D>> {
*
* @return Maximum distance
*/
- D getKNNDistance();
+ double getKNNDistance();
/**
* Add a distance-id pair to the heap unless the distance is too large.
@@ -69,8 +66,18 @@ public interface KNNHeap<D extends Distance<D>> {
*
* @param distance Distance value
* @param id ID number
+ * @return current k-distance
*/
- void insert(D distance, DBIDRef id);
+ double insert(double distance, DBIDRef id);
+
+ /**
+ * Add a distance-id pair to the heap unless the distance is too large.
+ *
+ * Use for existing pairs.
+ *
+ * @param e Existing distance pair
+ */
+ void insert(DoubleDBIDPair e);
/**
* Current size of heap.
@@ -78,14 +85,14 @@ public interface KNNHeap<D extends Distance<D>> {
* @return Heap size
*/
int size();
-
+
/**
* Test if the heap is empty.
*
* @return true when empty.
*/
boolean isEmpty();
-
+
/**
* Clear the heap.
*/
@@ -100,12 +107,12 @@ public interface KNNHeap<D extends Distance<D>> {
*
* @return largest element
*/
- DistanceDBIDPair<D> poll();
+ DoubleDBIDPair poll();
/**
* Peek at the <em>largest</em> element in the heap.
*
* @return The current largest element.
*/
- DistanceDBIDPair<D> peek();
+ DoubleDBIDPair peek();
} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/KNNList.java b/src/de/lmu/ifi/dbs/elki/database/ids/KNNList.java
index 61b75ba8..6d3dc778 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/KNNList.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/KNNList.java
@@ -1,10 +1,11 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
+package de.lmu.ifi.dbs.elki.database.ids;
+
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,7 +24,6 @@ package de.lmu.ifi.dbs.elki.database.ids.distance;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
/**
* Interface for kNN results.
@@ -54,11 +54,9 @@ import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
*
* @apiviz.landmark
*
- * @apiviz.composedOf DistanceDBIDPair
- *
- * @param <D> Distance type
+ * @apiviz.composedOf DoubleDBIDPair
*/
-public interface KNNList<D extends Distance<D>> extends DistanceDBIDList<D> {
+public interface KNNList extends DoubleDBIDList {
/**
* Size
*/
@@ -78,12 +76,12 @@ public interface KNNList<D extends Distance<D>> extends DistanceDBIDList<D> {
* @param index
*/
@Override
- public DistanceDBIDPair<D> get(int index);
+ public DoubleDBIDPair get(int index);
/**
* Get the distance to the k nearest neighbor, or maxdist otherwise.
*
* @return Maximum distance
*/
- public D getKNNDistance();
+ public double getKNNDistance();
} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/ModifiableDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/ModifiableDBIDs.java
index 1cd8c4e7..aa9a5052 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/ModifiableDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/ModifiableDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/ModifiableDistanceDBIDList.java b/src/de/lmu/ifi/dbs/elki/database/ids/ModifiableDoubleDBIDList.java
index afb15f93..2ae62345 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/ModifiableDistanceDBIDList.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/ModifiableDoubleDBIDList.java
@@ -1,10 +1,10 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
+package de.lmu.ifi.dbs.elki.database.ids;
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,23 +23,34 @@ package de.lmu.ifi.dbs.elki.database.ids.distance;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
+
/**
* Modifiable API for Distance-DBID results
*
* @author Erich Schubert
- *
- * @param <D> Distance type
+ *
+ * @apiviz.composedOf DoubleDBIDPair
*/
-public interface ModifiableDistanceDBIDList<D extends Distance<D>> extends DistanceDBIDList<D> {
+public interface ModifiableDoubleDBIDList extends DoubleDBIDList {
/**
* Add an object to this result.
*
* @param distance Distance to add
* @param id DBID to add
*/
- public void add(D distance, DBIDRef id);
+ void add(double distance, DBIDRef id);
+
+ /**
+ * Add an element.
+ *
+ * @param pair Pair to add
+ */
+ void add(DoubleDBIDPair pair);
+
+ /**
+ * Clear the list contents.
+ */
+ void clear();
/**
* Sort the result in ascending order
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/SetDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/SetDBIDs.java
index 3a92593e..0b316ca2 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/SetDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/SetDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/StaticDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/StaticDBIDs.java
index 2ba30d4b..24f6b585 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/StaticDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/StaticDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DistanceDBIDPair.java b/src/de/lmu/ifi/dbs/elki/database/ids/distance/DistanceDBIDPair.java
deleted file mode 100644
index a9d879d9..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DistanceDBIDPair.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
-
-/**
- * Pair containing a distance an an object ID
- *
- * Note: there is no getter for the object, as this is a {@link DBIDRef}.
- *
- * @author Erich Schubert
- *
- * @param <D> Distance
- */
-public interface DistanceDBIDPair<D extends Distance<D>> extends DBIDRef {
- /**
- * Get the distance.
- *
- * @return Distance
- */
- public D getDistance();
-
- /**
- * Compare to another result, by distance, smaller first.
- *
- * @param other Other result
- * @return Comparison result
- */
- public int compareByDistance(DistanceDBIDPair<D> other);
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDListIter.java b/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDListIter.java
deleted file mode 100644
index 68b2de1e..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDListIter.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-
-/**
- * Iterator for double valued distance-based query results.
- *
- * @author Erich Schubert
- */
-public interface DoubleDistanceDBIDListIter extends DistanceDBIDListIter<DoubleDistance> {
- /**
- * Get the distance
- *
- * @return distance
- */
- public double doubleDistance();
-
- /**
- * Get an object pair.
- *
- * @return object pair
- */
- @Override
- public DoubleDistanceDBIDPair getDistancePair();
-
- /**
- * Get the distance
- *
- * @deprecated Use {@link #doubleDistance} to avoid creating unnecessary
- * objects.
- *
- * @return distance
- */
- @Deprecated
- @Override
- public DoubleDistance getDistance();
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDPair.java b/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDPair.java
deleted file mode 100644
index 5286029b..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDPair.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-
-/**
- * Pair containing a double distance a DBID.
- *
- * There is no getter for the DBID, as this is a {@link DBIDRef} already.
- *
- * @author Erich Schubert
- */
-public interface DoubleDistanceDBIDPair extends DistanceDBIDPair<DoubleDistance> {
- /**
- * Get the distance.
- *
- * @deprecated Would produce a DoubleDistance object. Use {@link #doubleDistance} instead!
- *
- * @return Distance
- */
- @Override
- @Deprecated
- public DoubleDistance getDistance();
-
- /**
- * Get the distance.
- *
- * @return Distance
- */
- public double doubleDistance();
-} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDPairList.java b/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDPairList.java
deleted file mode 100644
index 58ce433d..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDPairList.java
+++ /dev/null
@@ -1,217 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import java.util.ArrayList;
-import java.util.Collections;
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDFactory;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
-import de.lmu.ifi.dbs.elki.distance.distanceresultlist.DistanceDBIDResultUtil;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-
-/**
- * Default class to keep a list of distance-object pairs.
- *
- * @author Erich Schubert
- *
- * @apiviz.composedOf DoubleDistanceDBIDPair
- * @apiviz.has DoubleDistanceDBIDListIter
- */
-public class DoubleDistanceDBIDPairList implements ModifiableDoubleDistanceDBIDList {
- /**
- * Actual storage.
- */
- final ArrayList<DoubleDistanceDBIDPair> storage;
-
- /**
- * Constructor.
- */
- public DoubleDistanceDBIDPairList() {
- super();
- storage = new ArrayList<>();
- }
-
- /**
- * Constructor.
- *
- * @param initialCapacity Capacity
- */
- public DoubleDistanceDBIDPairList(int initialCapacity) {
- super();
- storage = new ArrayList<>(initialCapacity);
- }
-
- /**
- * Add an element.
- *
- * @deprecated Pass a double value instead.
- *
- * @param dist Distance
- * @param id ID
- */
- @Override
- @Deprecated
- public void add(DoubleDistance dist, DBIDRef id) {
- storage.add(DBIDFactory.FACTORY.newDistancePair(dist.doubleValue(), id));
- }
-
- /**
- * Add an element.
- *
- * @param dist Distance
- * @param id ID
- */
- @Override
- public void add(double dist, DBIDRef id) {
- storage.add(DBIDFactory.FACTORY.newDistancePair(dist, id));
- }
-
- /**
- * Add an element.
- *
- * @param pair Pair to add
- */
- @Override
- public void add(DoubleDistanceDBIDPair pair) {
- storage.add(pair);
- }
-
- @Override
- public void clear() {
- storage.clear();
- }
-
- @Override
- public void sort() {
- Collections.sort(storage, DistanceDBIDResultUtil.distanceComparator());
- }
-
- @Override
- public int size() {
- return storage.size();
- }
-
- @Override
- public DoubleDistanceDBIDPair get(int off) {
- return storage.get(off);
- }
-
- @Override
- public DoubleDistanceDBIDListIter iter() {
- return new Itr();
- }
-
- @Override
- public boolean contains(DBIDRef o) {
- for(DBIDIter iter = iter(); iter.valid(); iter.advance()) {
- if(DBIDUtil.equal(iter, o)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean isEmpty() {
- return size() == 0;
- }
-
- @Override
- public String toString() {
- return DistanceDBIDResultUtil.toString(this);
- }
-
- /**
- * Iterator class.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- protected class Itr implements DoubleDistanceDBIDListIter {
- /**
- * Iterator position.
- */
- int pos = 0;
-
- @Override
- public int internalGetIndex() {
- return get(pos).internalGetIndex();
- }
-
- @Override
- public boolean valid() {
- return pos < size();
- }
-
- @Override
- public void advance() {
- pos++;
- }
-
- @Override
- @Deprecated
- public DoubleDistance getDistance() {
- return get(pos).getDistance();
- }
-
- @Override
- public double doubleDistance() {
- return get(pos).doubleDistance();
- }
-
- @Override
- public DoubleDistanceDBIDPair getDistancePair() {
- return get(pos);
- }
-
- @Override
- public String toString() {
- return valid() ? getDistancePair().toString() : "null";
- }
-
- @Override
- public int getOffset() {
- return pos;
- }
-
- @Override
- public void advance(int count) {
- pos += count;
- }
-
- @Override
- public void retract() {
- --pos;
- }
-
- @Override
- public void seek(int off) {
- pos = off;
- }
- }
-} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceKNNHeap.java b/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceKNNHeap.java
deleted file mode 100644
index ed687877..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceKNNHeap.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-
-/**
- * Interface for kNN heaps storing double distances and DBIDs.
- *
- * @author Erich Schubert
- */
-public interface DoubleDistanceKNNHeap extends KNNHeap<DoubleDistance> {
- /**
- * Add a distance-id pair to the heap unless the distance is too large.
- *
- * Compared to the super.add() method, this often saves the pair construction.
- *
- * @param distance Distance value
- * @param id ID number
- * @return updated k-distance
- */
- double insert(double distance, DBIDRef id);
-
- /**
- * Add a distance-id pair to the heap unless the distance is too large.
- *
- * Compared to the super.add() method, this often saves the pair construction.
- *
- * @param distance Distance value
- * @param id ID number
- */
- @Deprecated
- void insert(Double distance, DBIDRef id);
-
- /**
- * Add a distance-id pair to the heap unless the distance is too large.
- *
- * Use for existing pairs.
- *
- * @param e Existing distance pair
- */
- void insert(DoubleDistanceDBIDPair e);
-
- /**
- * {@inheritDoc}
- *
- * @deprecated if you know your distances are double-valued, you should be
- * using the primitive type.
- */
- @Override
- @Deprecated
- void insert(DoubleDistance dist, DBIDRef id);
-
- /**
- * Get the distance to the k nearest neighbor, or maxdist otherwise.
- *
- * @return Maximum distance
- */
- double doubleKNNDistance();
-
- /**
- * {@inheritDoc}
- *
- * @deprecated if you know your distances are double-valued, you should be
- * using the primitive type.
- */
- @Override
- @Deprecated
- DoubleDistance getKNNDistance();
-
- @Override
- DoubleDistanceDBIDPair poll();
-
- @Override
- DoubleDistanceDBIDPair peek();
-
- @Override
- DoubleDistanceKNNList toKNNList();
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceKNNList.java b/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceKNNList.java
deleted file mode 100644
index c54110ab..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceKNNList.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-
-/**
- * Double-valued KNN result.
- *
- * @author Erich Schubert
- */
-public interface DoubleDistanceKNNList extends KNNList<DoubleDistance> {
- /**
- * {@inheritDoc}
- *
- * @deprecated use doubleKNNDistance()!
- */
- @Override
- @Deprecated
- DoubleDistance getKNNDistance();
-
- /**
- * Get the kNN distance as double value.
- *
- * @return Distance
- */
- double doubleKNNDistance();
-
- @Override
- DoubleDistanceDBIDListIter iter();
-
- @Override
- DoubleDistanceDBIDPair get(int off);
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/ModifiableDoubleDistanceDBIDList.java b/src/de/lmu/ifi/dbs/elki/database/ids/distance/ModifiableDoubleDistanceDBIDList.java
deleted file mode 100644
index 4b29e3b6..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/ModifiableDoubleDistanceDBIDList.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDList;
-import de.lmu.ifi.dbs.elki.database.ids.distance.ModifiableDistanceDBIDList;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-
-/**
- * An object containing Double-DBID-Pairs.
- *
- * @author Erich Schubert
- */
-public interface ModifiableDoubleDistanceDBIDList extends DoubleDistanceDBIDList, ModifiableDistanceDBIDList<DoubleDistance> {
- /**
- * Add an element.
- *
- * @deprecated Pass a double value instead.
- *
- * @param dist Distance
- * @param id ID
- */
- @Override
- @Deprecated
- void add(DoubleDistance dist, DBIDRef id);
-
- /**
- * Add an element.
- *
- * @param dist Distance
- * @param id ID
- */
- void add(double dist, DBIDRef id);
-
- /**
- * Add an element.
- *
- * @param pair Pair to add
- */
- void add(DoubleDistanceDBIDPair pair);
-
- /**
- * Clear the list contents.
- */
- void clear();
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/package-info.java b/src/de/lmu/ifi/dbs/elki/database/ids/distance/package-info.java
deleted file mode 100644
index 7fefbedd..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/package-info.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Distance-DBID pairs, lists and heaps.
- */
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package de.lmu.ifi.dbs.elki.database.ids.distance;
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/AbstractKNNHeap.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/AbstractKNNHeap.java
deleted file mode 100644
index c42c728d..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/AbstractKNNHeap.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.generic;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.KNNHeap;
-import de.lmu.ifi.dbs.elki.distance.distanceresultlist.DistanceDBIDResultUtil;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
-import de.lmu.ifi.dbs.elki.utilities.datastructures.heap.TiedTopBoundedHeap;
-
-/**
- * Heap used for KNN management.
- *
- * @author Erich Schubert
- *
- * @param <P> pair type
- * @param <D> distance type
- */
-abstract class AbstractKNNHeap<P extends DistanceDBIDPair<D>, D extends Distance<D>> implements KNNHeap<D> {
- /**
- * The actual heap.
- */
- protected final TiedTopBoundedHeap<P> heap;
-
- /**
- * Constructor.
- *
- * @param k Maximum heap size (unless tied)
- */
- public AbstractKNNHeap(int k) {
- super();
- heap = new TiedTopBoundedHeap<>(k, DistanceDBIDResultUtil.BY_REVERSE_DISTANCE);
- }
-
- /**
- * Add a pair to the heap.
- *
- * @param pair Pair to add.
- */
- public abstract void insert(P pair);
-
- @Override
- public final int getK() {
- return heap.getMaxSize();
- }
-
- @Override
- public int size() {
- return heap.size();
- }
-
- @Override
- public P peek() {
- return heap.peek();
- }
-
- @Override
- public boolean isEmpty() {
- return heap.isEmpty();
- }
-
- @Override
- public void clear() {
- heap.clear();
- }
-
- @Override
- public P poll() {
- return heap.poll();
- }
-} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DBIDIterAdapter.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/DBIDIterAdapter.java
deleted file mode 100644
index 85fdcffd..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DBIDIterAdapter.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.generic;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import java.util.Iterator;
-
-import de.lmu.ifi.dbs.elki.database.ids.DBID;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDMIter;
-
-/**
- * Iterator for classic collections.
- *
- * @author Erich Schubert
- */
-public class DBIDIterAdapter implements DBIDMIter {
- /**
- * Current DBID.
- */
- DBID cur = null;
-
- /**
- * The real iterator.
- */
- Iterator<DBID> iter;
-
- /**
- * Constructor.
- *
- * @param iter Iterator
- */
- public DBIDIterAdapter(Iterator<DBID> iter) {
- super();
- this.iter = iter;
- advance();
- }
-
- @Override
- public boolean valid() {
- return cur != null;
- }
-
- @Override
- public void advance() {
- if(iter.hasNext()) {
- cur = iter.next();
- }
- else {
- cur = null;
- }
- }
-
- @Override
- public int internalGetIndex() {
- return cur.internalGetIndex();
- }
-
- @Override
- public void remove() {
- iter.remove();
- }
-} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DistanceDBIDPairKNNHeap.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/DistanceDBIDPairKNNHeap.java
deleted file mode 100644
index e102d716..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DistanceDBIDPairKNNHeap.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.generic;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDFactory;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
-
-/**
- * Heap for collecting kNN candidates with arbitrary distance types.
- *
- * For double distances, see {@link DoubleDistanceDBIDPairKNNHeap}
- *
- * <b>To instantiate, use {@link de.lmu.ifi.dbs.elki.database.ids.DBIDUtil#newHeap} instead!</b>
- *
- * @author Erich Schubert
- *
- * @param <D> Distance type
- */
-public class DistanceDBIDPairKNNHeap<D extends Distance<D>> extends AbstractKNNHeap<DistanceDBIDPair<D>, D> {
- /**
- * Cached distance to k nearest neighbor (to avoid going through {@link #peek}
- * each time).
- */
- protected D knndistance = null;
-
- /**
- * Constructor.
- *
- * <b>To instantiate, use {@link de.lmu.ifi.dbs.elki.database.ids.DBIDUtil#newHeap} instead!</b>
- *
- * @param k Heap size
- */
- public DistanceDBIDPairKNNHeap(int k) {
- super(k);
- }
-
- /**
- * Serialize to a {@link DistanceDBIDPairKNNList}. This empties the heap!
- *
- * @return KNNList with the heaps contents.
- */
- @Override
- public DistanceDBIDPairKNNList<D> toKNNList() {
- return new DistanceDBIDPairKNNList<>(this);
- }
-
- @Override
- public void insert(D distance, DBIDRef id) {
- if (size() < getK()) {
- heap.add(DBIDFactory.FACTORY.newDistancePair(distance, id));
- heapModified();
- return;
- }
- // size >= maxsize. Insert only when necessary.
- if (knndistance.compareTo(distance) >= 0) {
- // Replace worst element.
- heap.add(DBIDFactory.FACTORY.newDistancePair(distance, id));
- heapModified();
- }
- }
-
- @Override
- public void insert(DistanceDBIDPair<D> pair) {
- if (size() < getK() || knndistance.compareTo(pair.getDistance()) >= 0) {
- heap.add(pair);
- heapModified();
- }
- }
-
- // @Override
- protected void heapModified() {
- // super.heapModified();
- // Update threshold.
- if (size() >= getK()) {
- knndistance = heap.peek().getDistance();
- }
- }
-
- @Override
- public D getKNNDistance() {
- return knndistance;
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DistanceDBIDPairKNNList.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/DistanceDBIDPairKNNList.java
deleted file mode 100644
index bc5392d6..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DistanceDBIDPairKNNList.java
+++ /dev/null
@@ -1,211 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.generic;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDListIter;
-import de.lmu.ifi.dbs.elki.database.ids.distance.KNNHeap;
-import de.lmu.ifi.dbs.elki.database.ids.distance.KNNList;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
-import de.lmu.ifi.dbs.elki.utilities.datastructures.heap.Heap;
-
-/**
- * Finalized KNN List.
- *
- * @author Erich Schubert
- *
- * @param <D> Distance type
- */
-public class DistanceDBIDPairKNNList<D extends Distance<D>> implements KNNList<D> {
- /**
- * The value of k this was materialized for.
- */
- private final int k;
-
- /**
- * The actual data array.
- */
- private final Object[] data;
-
- /**
- * Constructor, to be called from KNNHeap only. Use {@link KNNHeap#toKNNList}
- * instead!
- *
- * @param heap Calling heap
- */
- protected DistanceDBIDPairKNNList(KNNHeap<D> heap) {
- super();
- this.data = new Object[heap.size()];
- this.k = heap.getK();
- // Get sorted data from heap; but in reverse.
- int i = heap.size();
- while (heap.size() > 0) {
- i--;
- assert (i >= 0);
- data[i] = heap.poll();
- }
- assert (data.length == 0 || data[0] != null);
- assert (heap.size() == 0);
- }
-
- /**
- * Constructor. With a KNNHeap, use {@link KNNHeap#toKNNList} instead!
- *
- * @param heap Calling heap
- * @param k K value
- */
- public DistanceDBIDPairKNNList(Heap<? extends DistanceDBIDPair<D>> heap, int k) {
- super();
- this.data = new Object[heap.size()];
- this.k = k;
- assert (heap.size() >= this.k) : "Heap doesn't contain enough objects!";
- // Get sorted data from heap; but in reverse.
- int i = heap.size();
- while (!heap.isEmpty()) {
- i--;
- assert (i >= 0);
- data[i] = heap.poll();
- }
- assert (data.length == 0 || data[0] != null);
- assert (heap.size() == 0);
- }
-
- @Override
- public int getK() {
- return k;
- }
-
- @Override
- public D getKNNDistance() {
- return get(getK() - 1).getDistance();
- }
-
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append("kNNList[");
- for (DistanceDBIDListIter<D> iter = this.iter(); iter.valid();) {
- buf.append(iter.getDistance()).append(':').append(DBIDUtil.toString(iter));
- iter.advance();
- if (iter.valid()) {
- buf.append(',');
- }
- }
- buf.append(']');
- return buf.toString();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public DistanceDBIDPair<D> get(int index) {
- return (DistanceDBIDPair<D>) data[index];
- }
-
- @Override
- public DistanceDBIDListIter<D> iter() {
- return new Itr();
- }
-
- @Override
- public int size() {
- return data.length;
- }
-
- @Override
- public boolean contains(DBIDRef o) {
- for (DBIDIter iter = iter(); iter.valid(); iter.advance()) {
- if (DBIDUtil.equal(iter, o)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean isEmpty() {
- return size() == 0;
- }
-
- /**
- * Iterator.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- private class Itr implements DistanceDBIDListIter<D> {
- /**
- * Cursor position.
- */
- private int pos = 0;
-
- @Override
- public int internalGetIndex() {
- return get(pos).internalGetIndex();
- }
-
- @Override
- public boolean valid() {
- return pos < data.length;
- }
-
- @Override
- public void advance() {
- pos++;
- }
-
- @Override
- public D getDistance() {
- return get(pos).getDistance();
- }
-
- @Override
- public DistanceDBIDPair<D> getDistancePair() {
- return get(pos);
- }
-
- @Override
- public int getOffset() {
- return pos;
- }
-
- @Override
- public void advance(int count) {
- pos += count;
- }
-
- @Override
- public void retract() {
- --pos;
- }
-
- @Override
- public void seek(int off) {
- pos += off;
- }
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceDBIDPairKNNHeap.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceDBIDPairKNNHeap.java
deleted file mode 100644
index 8e489a79..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceDBIDPairKNNHeap.java
+++ /dev/null
@@ -1,218 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.generic;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import java.util.Comparator;
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDFactory;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNHeap;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-
-/**
- * Heap for collecting double-valued KNN instances.
- *
- * See also: {@link de.lmu.ifi.dbs.elki.database.ids.DBIDUtil#newHeap}!
- *
- * Experiments have shown that it <em>can</em> be much more performant to track
- * the knndistance <em>outside</em> of the heap, and do comparisons on the
- * stack: <blockquote>
- *
- * <pre>
- * {@code
- * double knndist = Double.POSITIVE_INFINITY;
- * DoubleDistanceDBIDPairKNNHeap heap = new DoubleDistanceDBIDPairKNNHeap(k);
- * for (DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
- * double dist = computeDistance(iditer, ...);
- * if (dist < knndist) {
- * heap.add(dist, iditer);
- * if (heap.size() >= k) {
- * max = heap.doubleKNNDistance();
- * }
- * }
- * }
- * }
- * </pre>
- *
- * </blockquote>
- *
- * The reason probably is that {@code knndist} resides on the stack and can be
- * better optimized by the hotspot compiler.
- *
- * @author Erich Schubert
- */
-public class DoubleDistanceDBIDPairKNNHeap extends AbstractKNNHeap<DoubleDistanceDBIDPair, DoubleDistance> implements DoubleDistanceKNNHeap {
- /**
- * Comparator class.
- */
- public static final Comparator<DoubleDistanceDBIDPair> COMPARATOR = new Comp();
-
- /**
- * Reverse comparator.
- */
- public static final Comparator<DoubleDistanceDBIDPair> REVERSE_COMPARATOR = new RComp();
-
- /**
- * Cached distance to k nearest neighbor (to avoid going through {@link #peek}
- * too often).
- */
- protected double knndistance = Double.POSITIVE_INFINITY;
-
- /**
- * Constructor.
- *
- * See also: {@link de.lmu.ifi.dbs.elki.database.ids.DBIDUtil#newHeap}!
- *
- * @param k Heap size
- */
- public DoubleDistanceDBIDPairKNNHeap(int k) {
- super(k);
- }
-
- /**
- * Serialize to a {@link DoubleDistanceDBIDPairKNNList}. This empties the
- * heap!
- *
- * @return KNNList with the heaps contents.
- */
- @Override
- public DoubleDistanceDBIDPairKNNList toKNNList() {
- return new DoubleDistanceDBIDPairKNNList(this);
- }
-
- /**
- * Add a distance-id pair to the heap unless the distance is too large.
- *
- * Compared to the super.add() method, this often saves the pair construction.
- *
- * @param distance Distance value
- * @param id ID number
- * @return knn distance.
- */
- @Override
- public final double insert(final double distance, final DBIDRef id) {
- if (size() < getK() || knndistance >= distance) {
- heap.add(DBIDFactory.FACTORY.newDistancePair(distance, id));
- heapModified();
- }
- return knndistance;
- }
-
- /**
- * Add a distance-id pair to the heap unless the distance is too large.
- *
- * Compared to the super.add() method, this often saves the pair construction.
- *
- * @param distance Distance value
- * @param id ID number
- */
- @Override
- @Deprecated
- public final void insert(final Double distance, final DBIDRef id) {
- if (size() < getK() || knndistance >= distance) {
- heap.add(DBIDFactory.FACTORY.newDistancePair(distance, id));
- heapModified();
- }
- }
-
- // @Override
- protected void heapModified() {
- // super.heapModified();
- if (size() >= getK()) {
- knndistance = heap.peek().doubleDistance();
- }
- }
-
- @Override
- public void insert(final DoubleDistanceDBIDPair e) {
- if (size() < getK() || knndistance >= e.doubleDistance()) {
- heap.add(e);
- heapModified();
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated if you know your distances are double-valued, you should be
- * using the primitive type.
- *
- */
- @Override
- @Deprecated
- public void insert(DoubleDistance dist, DBIDRef id) {
- insert(dist.doubleValue(), id);
- }
-
- /**
- * Get the distance to the k nearest neighbor, or maxdist otherwise.
- *
- * @return Maximum distance
- */
- @Override
- public double doubleKNNDistance() {
- return knndistance;
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated if you know your distances are double-valued, you should be
- * using the primitive type.
- */
- @Override
- @Deprecated
- public DoubleDistance getKNNDistance() {
- return new DoubleDistance(knndistance);
- }
-
- /**
- * Comparator to use.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- protected static class Comp implements Comparator<DoubleDistanceDBIDPair> {
- @Override
- public int compare(DoubleDistanceDBIDPair o1, DoubleDistanceDBIDPair o2) {
- return -Double.compare(o1.doubleDistance(), o2.doubleDistance());
- }
- }
-
- /**
- * Comparator to use.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- protected static class RComp implements Comparator<DoubleDistanceDBIDPair> {
- @Override
- public int compare(DoubleDistanceDBIDPair o1, DoubleDistanceDBIDPair o2) {
- return Double.compare(o1.doubleDistance(), o2.doubleDistance());
- }
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceDBIDPairKNNList.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceDBIDPairKNNList.java
deleted file mode 100644
index c72529ad..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceDBIDPairKNNList.java
+++ /dev/null
@@ -1,257 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.generic;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import java.util.Collection;
-import java.util.Iterator;
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDListIter;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNList;
-import de.lmu.ifi.dbs.elki.database.ids.distance.KNNHeap;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-import de.lmu.ifi.dbs.elki.utilities.datastructures.heap.Heap;
-
-/**
- * Finalized KNN List.
- *
- * @author Erich Schubert
- *
- * @apiviz.composedOf DoubleDistanceDBIDPair
- * @apiviz.has DoubleDistanceDBIDListIter
- */
-public class DoubleDistanceDBIDPairKNNList implements DoubleDistanceKNNList {
- /**
- * The value of k this was materialized for.
- */
- private final int k;
-
- /**
- * The actual data array.
- */
- private final DoubleDistanceDBIDPair[] data;
-
- /**
- * Constructor. This will <em>clone</em> the given collection!
- *
- * @param col Existing collection
- * @param k K parameter
- */
- public DoubleDistanceDBIDPairKNNList(Collection<DoubleDistanceDBIDPair> col, int k) {
- super();
- this.data = new DoubleDistanceDBIDPair[col.size()];
- this.k = k;
- assert (col.size() >= this.k) : "Collection doesn't contain enough objects!";
- // Get sorted data from heap; but in reverse.
- Iterator<DoubleDistanceDBIDPair> it = col.iterator();
- for (int i = 0; it.hasNext(); i++) {
- data[i] = it.next();
- }
- assert (data.length == 0 || data[0] != null);
- }
-
- /**
- * Constructor, to be called from KNNHeap only. Use {@link KNNHeap#toKNNList}
- * instead!
- *
- * @param heap Calling heap
- */
- protected DoubleDistanceDBIDPairKNNList(DoubleDistanceDBIDPairKNNHeap heap) {
- super();
- this.data = new DoubleDistanceDBIDPair[heap.size()];
- this.k = heap.getK();
- // Get sorted data from heap; but in reverse.
- int i = heap.size();
- while (heap.size() > 0) {
- i--;
- assert (i >= 0);
- data[i] = heap.poll();
- }
- assert (data.length == 0 || data[0] != null);
- assert (heap.size() == 0);
- }
-
- /**
- * Constructor, to be called from KNNHeap only. Use {@link KNNHeap#toKNNList}
- * instead!
- *
- * @param heap Calling heap
- * @param k Target number of neighbors (before ties)
- */
- public DoubleDistanceDBIDPairKNNList(Heap<DoubleDistanceDBIDPair> heap, int k) {
- super();
- this.data = new DoubleDistanceDBIDPair[heap.size()];
- this.k = k;
- assert (heap.size() >= this.k) : "Heap doesn't contain enough objects!";
- // Get sorted data from heap; but in reverse.
- int i = heap.size();
- while (heap.size() > 0) {
- i--;
- assert (i >= 0);
- data[i] = heap.poll();
- }
- assert (data.length == 0 || data[0] != null);
- assert (heap.size() == 0);
- }
-
- @Override
- public int getK() {
- return k;
- }
-
- @Override
- @Deprecated
- public DoubleDistance getKNNDistance() {
- if (size() < k) {
- return DoubleDistance.INFINITE_DISTANCE;
- }
- return get(k - 1).getDistance();
- }
-
- @Override
- public double doubleKNNDistance() {
- if (size() < k) {
- return Double.POSITIVE_INFINITY;
- }
- return get(k - 1).doubleDistance();
- }
-
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append("kNNList[");
- for (DoubleDistanceDBIDListIter iter = this.iter(); iter.valid();) {
- buf.append(iter.doubleDistance()).append(':').append(DBIDUtil.toString(iter));
- iter.advance();
- if (iter.valid()) {
- buf.append(',');
- }
- }
- buf.append(']');
- return buf.toString();
- }
-
- @Override
- public DoubleDistanceDBIDPair get(int index) {
- return data[index];
- }
-
- @Override
- public DoubleDistanceDBIDListIter iter() {
- return new Itr();
- }
-
- @Override
- public int size() {
- return data.length;
- }
-
- @Override
- public boolean contains(DBIDRef o) {
- for (DBIDIter iter = iter(); iter.valid(); iter.advance()) {
- if (DBIDUtil.equal(iter, o)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean isEmpty() {
- return size() == 0;
- }
-
- /**
- * Iterator.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- private class Itr implements DoubleDistanceDBIDListIter {
- /**
- * Cursor position.
- */
- private int pos = 0;
-
- @Override
- public int internalGetIndex() {
- return get(pos).internalGetIndex();
- }
-
- @Override
- public boolean valid() {
- return pos < data.length;
- }
-
- @Override
- public void advance() {
- pos++;
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated use {@link #doubleDistance}!
- */
- @Override
- @Deprecated
- public DoubleDistance getDistance() {
- return get(pos).getDistance();
- }
-
- @Override
- public double doubleDistance() {
- return get(pos).doubleDistance();
- }
-
- @Override
- public DoubleDistanceDBIDPair getDistancePair() {
- return get(pos);
- }
-
- @Override
- public int getOffset() {
- return pos;
- }
-
- @Override
- public void advance(int count) {
- pos += count;
- }
-
- @Override
- public void retract() {
- --pos;
- }
-
- @Override
- public void seek(int off) {
- pos = off;
- }
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceDBIDPairKNNListHeap.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceDBIDPairKNNListHeap.java
deleted file mode 100644
index ca00129b..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceDBIDPairKNNListHeap.java
+++ /dev/null
@@ -1,289 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.generic;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import java.util.Arrays;
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDListIter;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNHeap;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNList;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-
-/**
- * Finalized KNN List.
- *
- * @author Erich Schubert
- *
- * @apiviz.composedOf DoubleDistanceDBIDPair
- * @apiviz.has DoubleDistanceDBIDListIter
- */
-public class DoubleDistanceDBIDPairKNNListHeap implements DoubleDistanceKNNList, DoubleDistanceKNNHeap {
- /**
- * The value of k this was materialized for.
- */
- private final int k;
-
- /**
- * The actual data array.
- */
- private DoubleDistanceDBIDPair[] data;
-
- /**
- * Current size
- */
- private int size;
-
- /**
- * Constructor.
- *
- * @param k K parameter
- */
- public DoubleDistanceDBIDPairKNNListHeap(int k) {
- super();
- this.data = new DoubleDistanceDBIDPair[k + 11];
- this.k = k;
- }
-
- @Override
- public void clear() {
- size = 0;
- Arrays.fill(data, null);
- }
-
- @Override
- public double insert(double distance, DBIDRef id) {
- if (size < k || distance <= data[k - 1].doubleDistance()) {
- insert(DBIDUtil.newDistancePair(distance, id));
- }
- return (size < k) ? Double.POSITIVE_INFINITY : get(k - 1).doubleDistance();
- }
-
- @Override
- @Deprecated
- public void insert(Double distance, DBIDRef id) {
- insert(DBIDUtil.newDistancePair(distance.doubleValue(), id));
- }
-
- @Override
- @Deprecated
- public void insert(DoubleDistance dist, DBIDRef id) {
- insert(DBIDUtil.newDistancePair(dist.doubleValue(), id));
- }
-
- @Override
- public void insert(DoubleDistanceDBIDPair e) {
- if (size >= k) {
- if (e.doubleDistance() > data[size - 1].doubleDistance()) {
- return;
- }
- // Ensure we have enough space.
- final int len = data.length;
- if (size > len) {
- final int newlength = len + (len >>> 1);
- assert (newlength > size);
- data = Arrays.copyOf(data, newlength);
- }
- }
- insertionSort(e);
- // Truncate if necessary:
- if (size > k && data[k].doubleDistance() > data[k - 1].doubleDistance()) {
- size = k;
- }
- }
-
- /**
- * Perform insertion sort.
- *
- * @param obj Object to insert
- */
- private void insertionSort(DoubleDistanceDBIDPair obj) {
- // Insertion sort:
- int pos = size;
- while (pos > 0) {
- DoubleDistanceDBIDPair pobj = data[pos - 1];
- if (pobj.doubleDistance() <= obj.doubleDistance()) {
- break;
- }
- data[pos] = pobj;
- --pos;
- }
- data[pos] = obj;
- ++size;
- }
-
- @Override
- public DoubleDistanceDBIDPair poll() {
- assert (size > 0);
- return data[size--];
- }
-
- @Override
- public DoubleDistanceDBIDPair peek() {
- assert (size > 0);
- return data[size - 1];
- }
-
- @Override
- public DoubleDistanceKNNList toKNNList() {
- return this;
- }
-
- @Override
- public int getK() {
- return k;
- }
-
- @Override
- @Deprecated
- public DoubleDistance getKNNDistance() {
- if (size < k) {
- return DoubleDistance.INFINITE_DISTANCE;
- }
- return get(k - 1).getDistance();
- }
-
- @Override
- public double doubleKNNDistance() {
- return (size < k) ? Double.POSITIVE_INFINITY : get(k - 1).doubleDistance();
- }
-
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append("kNNList[");
- for (DoubleDistanceDBIDListIter iter = this.iter(); iter.valid();) {
- buf.append(iter.doubleDistance()).append(':').append(DBIDUtil.toString(iter));
- iter.advance();
- if (iter.valid()) {
- buf.append(',');
- }
- }
- buf.append(']');
- return buf.toString();
- }
-
- @Override
- public DoubleDistanceDBIDPair get(int index) {
- return data[index];
- }
-
- @Override
- public DoubleDistanceDBIDListIter iter() {
- return new Itr();
- }
-
- @Override
- public int size() {
- return data.length;
- }
-
- @Override
- public boolean contains(DBIDRef o) {
- for (DBIDIter iter = iter(); iter.valid(); iter.advance()) {
- if (DBIDUtil.equal(iter, o)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean isEmpty() {
- return size() == 0;
- }
-
- /**
- * Iterator.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- private class Itr implements DoubleDistanceDBIDListIter {
- /**
- * Cursor position.
- */
- private int pos = 0;
-
- @Override
- public int internalGetIndex() {
- return get(pos).internalGetIndex();
- }
-
- @Override
- public boolean valid() {
- return pos < data.length;
- }
-
- @Override
- public void advance() {
- pos++;
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated use {@link #doubleDistance}!
- */
- @Override
- @Deprecated
- public DoubleDistance getDistance() {
- return get(pos).getDistance();
- }
-
- @Override
- public double doubleDistance() {
- return get(pos).doubleDistance();
- }
-
- @Override
- public DoubleDistanceDBIDPair getDistancePair() {
- return get(pos);
- }
-
- @Override
- public int getOffset() {
- return pos;
- }
-
- @Override
- public void advance(int count) {
- pos += count;
- }
-
- @Override
- public void retract() {
- --pos;
- }
-
- @Override
- public void seek(int off) {
- pos = off;
- }
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/GenericDistanceDBIDList.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/GenericDistanceDBIDList.java
deleted file mode 100644
index 911c58e7..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/GenericDistanceDBIDList.java
+++ /dev/null
@@ -1,206 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.generic;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import java.util.Arrays;
-import java.util.Comparator;
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDFactory;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDListIter;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.ModifiableDistanceDBIDList;
-import de.lmu.ifi.dbs.elki.distance.distanceresultlist.DistanceDBIDResultUtil;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
-
-/**
- * Default class to keep a list of distance-object pairs.
- *
- * @author Erich Schubert
- *
- * @param <D> Distance type
- */
-public class GenericDistanceDBIDList<D extends Distance<D>> implements ModifiableDistanceDBIDList<D> {
- /**
- * Actual storage.
- */
- Object[] storage;
-
- /**
- * Current size.
- */
- int size = 0;
-
- /**
- * Constructor.
- */
- public GenericDistanceDBIDList() {
- super();
- storage = new Object[21];
- }
-
- /**
- * Constructor.
- *
- * @param initialCapacity Capacity
- */
- public GenericDistanceDBIDList(int initialCapacity) {
- super();
- storage = new Object[initialCapacity];
- }
-
- @Override
- public void add(D dist, DBIDRef id) {
- ensureSize(size + 1);
- storage[size] = DBIDFactory.FACTORY.newDistancePair(dist, id);
- ++size;
- }
-
- /**
- * Add a prepared pair.
- *
- * @param pair Pair to add
- */
- public void add(DistanceDBIDPair<D> pair) {
- ensureSize(size + 1);
- storage[size] = pair;
- ++size;
- }
-
- private void ensureSize(int size) {
- if (size < storage.length) {
- storage = Arrays.copyOf(storage, (size << 1) + 1);
- }
- }
-
- @Override
- public void sort() {
- @SuppressWarnings("unchecked")
- final Comparator<Object> comp = (Comparator<Object>) DistanceDBIDResultUtil.distanceComparator();
- Arrays.sort(storage, 0, size, comp);
- // DistanceDBIDResultUtil.sortByDistance(storage);
- }
-
- @Override
- public int size() {
- return size;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public DistanceDBIDPair<D> get(int off) {
- return (DistanceDBIDPair<D>) storage[off];
- }
-
- @Override
- public DistanceDBIDListIter<D> iter() {
- return new Itr();
- }
-
- @Override
- public boolean contains(DBIDRef o) {
- for (DBIDIter iter = iter(); iter.valid(); iter.advance()) {
- if (DBIDUtil.equal(iter, o)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean isEmpty() {
- return size() == 0;
- }
-
- @Override
- public String toString() {
- return DistanceDBIDResultUtil.toString(this);
- }
-
- /**
- * Iterator class.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- protected class Itr implements DistanceDBIDListIter<D> {
- /**
- * Iterator position.
- */
- int pos = 0;
-
- @Override
- public int internalGetIndex() {
- return get(pos).internalGetIndex();
- }
-
- @Override
- public boolean valid() {
- return pos < size();
- }
-
- @Override
- public void advance() {
- pos++;
- }
-
- @Override
- public D getDistance() {
- return get(pos).getDistance();
- }
-
- @Override
- public DistanceDBIDPair<D> getDistancePair() {
- return get(pos);
- }
-
- @Override
- public String toString() {
- return valid() ? getDistancePair().toString() : "null";
- }
-
- @Override
- public int getOffset() {
- return pos;
- }
-
- @Override
- public void advance(int count) {
- pos += count;
- }
-
- @Override
- public void retract() {
- --pos;
- }
-
- @Override
- public void seek(int off) {
- pos = off;
- }
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/KNNSubList.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/KNNSubList.java
index 3d7863fd..6bfb05b0 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/KNNSubList.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/generic/KNNSubList.java
@@ -1,18 +1,10 @@
package de.lmu.ifi.dbs.elki.database.ids.generic;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDListIter;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.KNNList;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
-
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -30,15 +22,19 @@ import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
+import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
+import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair;
+import de.lmu.ifi.dbs.elki.database.ids.KNNList;
/**
* Sublist of an existing result to contain only the first k elements.
*
* @author Erich Schubert
- *
- * @param <D> Distance
*/
-public class KNNSubList<D extends Distance<D>> implements KNNList<D> {
+public class KNNSubList implements KNNList {
/**
* Parameter k.
*/
@@ -52,7 +48,7 @@ public class KNNSubList<D extends Distance<D>> implements KNNList<D> {
/**
* Wrapped inner result.
*/
- private final KNNList<D> inner;
+ private final KNNList inner;
/**
* Constructor.
@@ -60,22 +56,24 @@ public class KNNSubList<D extends Distance<D>> implements KNNList<D> {
* @param inner Inner instance
* @param k k value
*/
- public KNNSubList(KNNList<D> inner, int k) {
+ public KNNSubList(KNNList inner, int k) {
this.inner = inner;
this.k = k;
// Compute list size
- // TODO: optimize for double distances.
- {
- DistanceDBIDPair<D> dist = inner.get(k);
+ if(k < inner.getK()) {
+ DoubleDBIDPair dist = inner.get(k);
int i = k;
- while (i + 1 < inner.size()) {
- if (dist.compareByDistance(inner.get(i + 1)) < 0) {
+ while(i + 1 < inner.size()) {
+ if(dist.doubleValue() < inner.get(i + 1).doubleValue()) {
break;
}
i++;
}
size = i;
}
+ else {
+ size = inner.size();
+ }
}
@Override
@@ -84,25 +82,25 @@ public class KNNSubList<D extends Distance<D>> implements KNNList<D> {
}
@Override
- public DistanceDBIDPair<D> get(int index) {
+ public DoubleDBIDPair get(int index) {
assert (index < size) : "Access beyond design size of list.";
return inner.get(index);
}
@Override
- public D getKNNDistance() {
- return inner.get(k).getDistance();
+ public double getKNNDistance() {
+ return inner.get(k).doubleValue();
}
@Override
- public DistanceDBIDListIter<D> iter() {
+ public DoubleDBIDListIter iter() {
return new Itr();
}
@Override
public boolean contains(DBIDRef o) {
- for (DBIDIter iter = iter(); iter.valid(); iter.advance()) {
- if (DBIDUtil.equal(iter, o)) {
+ for(DBIDIter iter = iter(); iter.valid(); iter.advance()) {
+ if(DBIDUtil.equal(iter, o)) {
return true;
}
}
@@ -126,7 +124,7 @@ public class KNNSubList<D extends Distance<D>> implements KNNList<D> {
*
* @apiviz.exclude
*/
- private class Itr implements DistanceDBIDListIter<D> {
+ private class Itr implements DoubleDBIDListIter {
/**
* Current position.
*/
@@ -134,21 +132,22 @@ public class KNNSubList<D extends Distance<D>> implements KNNList<D> {
@Override
public boolean valid() {
- return pos < size;
+ return pos < size && pos >= 0;
}
@Override
- public void advance() {
+ public Itr advance() {
pos++;
+ return this;
}
@Override
- public D getDistance() {
- return inner.get(pos).getDistance();
+ public double doubleValue() {
+ return inner.get(pos).doubleValue();
}
@Override
- public DistanceDBIDPair<D> getDistancePair() {
+ public DoubleDBIDPair getPair() {
return inner.get(pos);
}
@@ -163,18 +162,21 @@ public class KNNSubList<D extends Distance<D>> implements KNNList<D> {
}
@Override
- public void advance(int count) {
- pos -= count;
+ public Itr advance(int count) {
+ pos += count;
+ return this;
}
@Override
- public void retract() {
+ public Itr retract() {
--pos;
+ return this;
}
@Override
- public void seek(int off) {
+ public Itr seek(int off) {
pos = off;
+ return this;
}
}
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/MaskedDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/MaskedDBIDs.java
index 2b481fca..19162450 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/MaskedDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/generic/MaskedDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.generic;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -35,6 +35,8 @@ import de.lmu.ifi.dbs.elki.database.ids.DBIDs;
/**
* View on an ArrayDBIDs masked using a BitMask for efficient mask changing.
*
+ * FIXME: switch to long[] instead of BitSet
+ *
* @author Erich Schubert
*
* @apiviz.uses DBIDs
@@ -137,8 +139,9 @@ public class MaskedDBIDs implements DBIDs {
}
@Override
- public void advance() {
+ public DBIDIter advance() {
pos = bits.nextSetBit(pos + 1);
+ return this;
}
@Override
@@ -180,8 +183,9 @@ public class MaskedDBIDs implements DBIDs {
}
@Override
- public void advance() {
+ public DBIDIter advance() {
pos = bits.nextClearBit(pos + 1);
+ return this;
}
@Override
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/MergedDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/MergedDBIDs.java
deleted file mode 100644
index 7df6975c..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/MergedDBIDs.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.generic;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDs;
-import de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException;
-
-/**
- * Merge the IDs of multiple layers into one.
- *
- * @author Erich Schubert
- *
- * @apiviz.uses de.lmu.ifi.dbs.elki.database.ids.DBIDs
- */
-// TODO: include ID mapping?
-public class MergedDBIDs implements DBIDs {
- /**
- * Childs to merge
- */
- DBIDs childs[];
-
- /**
- * Constructor.
- *
- * @param childs
- */
- public MergedDBIDs(DBIDs... childs) {
- super();
- this.childs = childs;
- }
-
- @Override
- public DBIDIter iter() {
- throw new AbortException("Merged iterators not completely implemented yet!");
- }
-
- @Override
- public int size() {
- int si = 0;
- for(DBIDs child : childs) {
- si += child.size();
- }
- return si;
- }
-
- @Override
- public boolean isEmpty() {
- return size() == 0;
- }
-
- @Override
- public boolean contains(DBIDRef o) {
- for(DBIDs child : childs) {
- if(child.contains(o)) {
- return true;
- }
- }
- return false;
- }
-} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/UnmodifiableArrayDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/UnmodifiableArrayDBIDs.java
index 49c6b07e..0b5d8ed2 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/UnmodifiableArrayDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/generic/UnmodifiableArrayDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.generic;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -131,8 +131,9 @@ public class UnmodifiableArrayDBIDs implements ArrayStaticDBIDs {
}
@Override
- public void advance() {
+ public DBIDArrayIter advance() {
it.advance();
+ return this;
}
@Override
@@ -141,18 +142,21 @@ public class UnmodifiableArrayDBIDs implements ArrayStaticDBIDs {
}
@Override
- public void advance(int count) {
+ public DBIDArrayIter advance(int count) {
it.advance(count);
+ return this;
}
@Override
- public void retract() {
+ public DBIDArrayIter retract() {
it.retract();
+ return this;
}
@Override
- public void seek(int off) {
+ public DBIDArrayIter seek(int off) {
it.seek(off);
+ return this;
}
@Override
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/UnmodifiableDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/UnmodifiableDBIDs.java
index 458dab3f..0f4920a5 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/UnmodifiableDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/generic/UnmodifiableDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.generic;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -109,8 +109,9 @@ public class UnmodifiableDBIDs implements StaticDBIDs {
}
@Override
- public void advance() {
+ public DBIDIter advance() {
it.advance();
+ return this;
}
@Override
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/package-info.java b/src/de/lmu/ifi/dbs/elki/database/ids/generic/package-info.java
index 9920cac7..e2232e18 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/package-info.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/generic/package-info.java
@@ -7,7 +7,7 @@
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
-Copyright (C) 2013
+Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/AbstractIntegerDBIDFactory.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/AbstractIntegerDBIDFactory.java
index 72ecb9be..2317ac43 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/AbstractIntegerDBIDFactory.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/AbstractIntegerDBIDFactory.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -31,17 +31,11 @@ import de.lmu.ifi.dbs.elki.database.ids.DBIDVar;
import de.lmu.ifi.dbs.elki.database.ids.DBIDs;
import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair;
import de.lmu.ifi.dbs.elki.database.ids.HashSetModifiableDBIDs;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNHeap;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNList;
-import de.lmu.ifi.dbs.elki.database.ids.distance.KNNHeap;
-import de.lmu.ifi.dbs.elki.database.ids.distance.KNNList;
-import de.lmu.ifi.dbs.elki.database.ids.generic.DistanceDBIDPairKNNHeap;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
-import de.lmu.ifi.dbs.elki.persistent.FixedSizeByteBufferSerializer;
+import de.lmu.ifi.dbs.elki.database.ids.KNNHeap;
+import de.lmu.ifi.dbs.elki.database.ids.KNNList;
+import de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteBufferSerializer;
+import de.lmu.ifi.dbs.elki.utilities.io.FixedSizeByteBufferSerializer;
/**
* Abstract base class for DBID factories.
@@ -89,7 +83,7 @@ abstract class AbstractIntegerDBIDFactory implements DBIDFactory {
@Override
public String toString(DBIDRef id) {
- return Integer.toString(id.internalGetIndex());
+ return (id != null) ? Integer.toString(id.internalGetIndex()) : "null";
}
@Override
@@ -134,60 +128,32 @@ abstract class AbstractIntegerDBIDFactory implements DBIDFactory {
@Override
public DoubleDBIDPair newPair(double val, DBIDRef id) {
- return new IntegerDoubleDBIDPair(val, id.internalGetIndex());
+ return new DoubleIntegerDBIDPair(val, id.internalGetIndex());
}
- @SuppressWarnings("unchecked")
@Override
- public <D extends Distance<D>> DistanceDBIDPair<D> newDistancePair(D val, DBIDRef id) {
- if(val instanceof DoubleDistance) {
- return (DistanceDBIDPair<D>) new DoubleDistanceIntegerDBIDPair(((DoubleDistance) val).doubleValue(), id.internalGetIndex());
- }
- return new DistanceIntegerDBIDPair<>(val, id.internalGetIndex());
- }
-
- @Override
- public DoubleDistanceDBIDPair newDistancePair(double val, DBIDRef id) {
- return new DoubleDistanceIntegerDBIDPair(val, id.internalGetIndex());
+ public KNNHeap newHeap(int k) {
+ return new DoubleIntegerDBIDKNNHeap(k);
}
- @SuppressWarnings("unchecked")
@Override
- public <D extends Distance<D>> KNNHeap<D> newHeap(D factory, int k) {
- if(factory instanceof DoubleDistance) {
- return (KNNHeap<D>) newDoubleDistanceHeap(k);
+ public KNNHeap newHeap(KNNList exist) {
+ KNNHeap heap = newHeap(exist.getK());
+ // Insert backwards, as this will produce a proper heap
+ for(int i = exist.size() - 1; i >= 0; i--) {
+ heap.insert(exist.get(i));
}
- return new DistanceDBIDPairKNNHeap<>(k);
+ return heap;
}
- @SuppressWarnings("unchecked")
@Override
- public <D extends Distance<D>> KNNHeap<D> newHeap(KNNList<D> exist) {
- if(exist instanceof DoubleDistanceKNNList) {
- DoubleDistanceKNNHeap heap = newDoubleDistanceHeap(exist.getK());
- // Insert backwards, as this will produce a proper heap
- for(int i = exist.size() - 1; i >= 0; i--) {
- heap.insert((DoubleDistanceDBIDPair) exist.get(i));
- }
- return (KNNHeap<D>) heap;
- }
- else {
- DistanceDBIDPairKNNHeap<D> heap = new DistanceDBIDPairKNNHeap<>(exist.getK());
- // Insert backwards, as this will produce a proper heap
- for(int i = exist.size() - 1; i >= 0; i--) {
- heap.insert(exist.get(i));
- }
- return heap;
- }
+ public ModifiableDoubleDBIDList newDistanceDBIDList(int size) {
+ return new DoubleIntegerDBIDList(size);
}
@Override
- public DoubleDistanceKNNHeap newDoubleDistanceHeap(int k) {
- // TODO: benchmark threshold!
- if(k > 1000) {
- return new DoubleDistanceIntegerDBIDKNNHeap(k);
- }
- return new DoubleDistanceIntegerDBIDSortedKNNList(k);
+ public ModifiableDoubleDBIDList newDistanceDBIDList() {
+ return new DoubleIntegerDBIDList();
}
@Override
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/ArrayModifiableIntegerDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/ArrayModifiableIntegerDBIDs.java
index 2fc94ddb..1ead59b6 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/ArrayModifiableIntegerDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/ArrayModifiableIntegerDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -38,7 +38,7 @@ import de.lmu.ifi.dbs.elki.database.ids.DBIDs;
*
* @author Erich Schubert
*/
-public class ArrayModifiableIntegerDBIDs implements ArrayModifiableDBIDs, IntegerArrayDBIDs {
+class ArrayModifiableIntegerDBIDs implements ArrayModifiableDBIDs, IntegerArrayDBIDs {
/**
* The actual Trove array list.
*/
@@ -292,8 +292,9 @@ public class ArrayModifiableIntegerDBIDs implements ArrayModifiableDBIDs, Intege
}
@Override
- public void advance() {
+ public Itr advance() {
++pos;
+ return this;
}
@Override
@@ -302,18 +303,21 @@ public class ArrayModifiableIntegerDBIDs implements ArrayModifiableDBIDs, Intege
}
@Override
- public void advance(int count) {
+ public Itr advance(int count) {
pos += count;
+ return this;
}
@Override
- public void retract() {
+ public Itr retract() {
--pos;
+ return this;
}
@Override
- public void seek(int off) {
+ public Itr seek(int off) {
pos = off;
+ return this;
}
@Override
@@ -423,8 +427,9 @@ public class ArrayModifiableIntegerDBIDs implements ArrayModifiableDBIDs, Intege
}
@Override
- public void advance() {
+ public SliceItr advance() {
++pos;
+ return this;
}
@Override
@@ -433,18 +438,21 @@ public class ArrayModifiableIntegerDBIDs implements ArrayModifiableDBIDs, Intege
}
@Override
- public void advance(int count) {
+ public SliceItr advance(int count) {
pos += count;
+ return this;
}
@Override
- public void retract() {
+ public SliceItr retract() {
--pos;
+ return this;
}
@Override
- public void seek(int off) {
+ public SliceItr seek(int off) {
pos = off;
+ return this;
}
@Override
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/ArrayStaticIntegerDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/ArrayStaticIntegerDBIDs.java
index fcb426ac..60d43ff8 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/ArrayStaticIntegerDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/ArrayStaticIntegerDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -37,7 +37,7 @@ import de.lmu.ifi.dbs.elki.logging.LoggingUtil;
*
* @author Erich Schubert
*/
-public class ArrayStaticIntegerDBIDs implements IntegerArrayStaticDBIDs {
+class ArrayStaticIntegerDBIDs implements IntegerArrayStaticDBIDs {
/**
* The actual storage.
*/
@@ -48,7 +48,7 @@ public class ArrayStaticIntegerDBIDs implements IntegerArrayStaticDBIDs {
*
* @param ids Array of ids.
*/
- public ArrayStaticIntegerDBIDs(int... ids) {
+ protected ArrayStaticIntegerDBIDs(int... ids) {
super();
this.store = ids;
}
@@ -123,23 +123,27 @@ public class ArrayStaticIntegerDBIDs implements IntegerArrayStaticDBIDs {
}
@Override
- public void advance() {
+ public Itr advance() {
pos++;
+ return this;
}
@Override
- public void advance(int count) {
+ public Itr advance(int count) {
pos += 0;
+ return this;
}
@Override
- public void retract() {
+ public Itr retract() {
pos--;
+ return this;
}
@Override
- public void seek(int off) {
+ public Itr seek(int off) {
pos = off;
+ return this;
}
@Override
@@ -262,8 +266,9 @@ public class ArrayStaticIntegerDBIDs implements IntegerArrayStaticDBIDs {
}
@Override
- public void advance() {
+ public SliceItr advance() {
++pos;
+ return this;
}
@Override
@@ -272,18 +277,21 @@ public class ArrayStaticIntegerDBIDs implements IntegerArrayStaticDBIDs {
}
@Override
- public void advance(int count) {
+ public SliceItr advance(int count) {
pos += count;
+ return this;
}
@Override
- public void retract() {
+ public SliceItr retract() {
--pos;
+ return this;
}
@Override
- public void seek(int off) {
+ public SliceItr seek(int off) {
pos = begin + off;
+ return this;
}
@Override
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DistanceIntegerDBIDPair.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DistanceIntegerDBIDPair.java
deleted file mode 100644
index a8930b87..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DistanceIntegerDBIDPair.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.integer;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-import de.lmu.ifi.dbs.elki.utilities.Util;
-
-/**
- * Class storing a double distance a DBID.
- *
- * @author Erich Schubert
- *
- * @param <D> Distance type
- */
-class DistanceIntegerDBIDPair<D extends Distance<D>> implements DistanceDBIDPair<D>, IntegerDBIDRef {
- /**
- * The distance value.
- */
- D distance;
-
- /**
- * The integer DBID.
- */
- int id;
-
- /**
- * Constructor.
- *
- * @param distance Distance
- * @param id Object ID
- */
- protected DistanceIntegerDBIDPair(D distance, int id) {
- super();
- this.distance = distance;
- this.id = id;
- }
-
- @Override
- public D getDistance() {
- return distance;
- }
-
- @Override
- public int internalGetIndex() {
- return id;
- }
-
- @Override
- public int compareByDistance(DistanceDBIDPair<D> o) {
- return distance.compareTo(o.getDistance());
- }
-
- @Override
- public String toString() {
- return distance.toString() + ":" + id;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o instanceof DistanceIntegerDBIDPair) {
- DistanceIntegerDBIDPair<?> p = (DistanceIntegerDBIDPair<?>) o;
- return (this.id == p.id) && distance.equals(p.getDistance());
- }
- if (o instanceof DoubleDistanceIntegerDBIDPair && distance instanceof DoubleDistance) {
- DoubleDistanceIntegerDBIDPair p = (DoubleDistanceIntegerDBIDPair) o;
- return (this.id == p.id) && (Double.compare(((DoubleDistance) this.distance).doubleValue(), p.distance) == 0);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Util.mixHashCodes(distance.hashCode(), id);
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDPair.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDPair.java
deleted file mode 100644
index 1f3b2a45..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDPair.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.integer;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-import de.lmu.ifi.dbs.elki.utilities.Util;
-
-/**
- * Class storing a double distance a DBID.
- *
- * @author Erich Schubert
- */
-class DoubleDistanceIntegerDBIDPair implements DoubleDistanceDBIDPair, IntegerDBIDRef {
- /**
- * The distance value.
- */
- final double distance;
-
- /**
- * The integer DBID.
- */
- final int id;
-
- /**
- * Constructor.
- *
- * @param distance Distance value
- * @param id integer object ID
- */
- protected DoubleDistanceIntegerDBIDPair(double distance, int id) {
- super();
- this.distance = distance;
- this.id = id;
- }
-
- @Override
- public double doubleDistance() {
- return distance;
- }
-
- @Override
- @Deprecated
- public DoubleDistance getDistance() {
- return new DoubleDistance(distance);
- }
-
- @Override
- public int internalGetIndex() {
- return id;
- }
-
- @Override
- public int compareByDistance(DistanceDBIDPair<DoubleDistance> o) {
- if (o instanceof DoubleDistanceDBIDPair) {
- return Double.compare(distance, ((DoubleDistanceDBIDPair) o).doubleDistance());
- }
- return Double.compare(distance, o.getDistance().doubleValue());
- }
-
- @Override
- public String toString() {
- return distance + ":" + id;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o instanceof DoubleDistanceIntegerDBIDPair) {
- DoubleDistanceIntegerDBIDPair p = (DoubleDistanceIntegerDBIDPair) o;
- return (this.id == p.id) && (Double.compare(this.distance, p.distance) == 0);
- }
- if (o instanceof DistanceIntegerDBIDPair) {
- DistanceIntegerDBIDPair<?> p = (DistanceIntegerDBIDPair<?>) o;
- if (p.distance instanceof DoubleDistance) {
- return (this.id == p.id) && (Double.compare(this.distance, ((DoubleDistance) p.distance).doubleValue()) == 0);
- }
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- long bits = Double.doubleToLongBits(distance);
- return Util.mixHashCodes((int) (bits ^ (bits >>> 32)), id);
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDPairKNNListHeap.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDPairKNNListHeap.java
deleted file mode 100644
index aa0a9739..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDPairKNNListHeap.java
+++ /dev/null
@@ -1,339 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.integer;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDListIter;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNHeap;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNList;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
-
-/**
- * Finalized KNN List.
- *
- * @author Erich Schubert
- *
- * @apiviz.composedOf DoubleDistanceDBIDPair
- * @apiviz.has DoubleDistanceDBIDListIter
- */
-public class DoubleDistanceIntegerDBIDPairKNNListHeap implements DoubleDistanceKNNList, DoubleDistanceKNNHeap {
- /**
- * The value of k this was materialized for.
- */
- private final int k;
-
- /**
- * The actual data array.
- */
- private DoubleDistanceIntegerDBIDPair[] data;
-
- /**
- * Current size
- */
- private int size;
-
- /**
- * Constructor.
- *
- * @param k K parameter
- */
- public DoubleDistanceIntegerDBIDPairKNNListHeap(int k) {
- super();
- this.data = new DoubleDistanceIntegerDBIDPair[k + 5];
- this.k = k;
- this.size = 0;
- }
-
- @Override
- public void clear() {
- for(int i = 0; i < size; i++) {
- data[i] = null; // discard
- }
- size = 0;
- }
-
- @Override
- public double insert(double distance, DBIDRef id) {
- final int kminus1 = k - 1;
- if(size < k || distance <= data[kminus1].doubleDistance()) {
- // Ensure we have enough space.
- if(size > data.length) {
- grow();
- }
- insertionSort(new DoubleDistanceIntegerDBIDPair(distance, id.internalGetIndex()));
- // Truncate if necessary:
- if(size > k && data[k].doubleDistance() > data[kminus1].doubleDistance()) {
- truncate();
- }
- }
- return (size < k) ? Double.POSITIVE_INFINITY : get(kminus1).doubleDistance();
- }
-
- private void truncate() {
- for(int i = k; i < size; i++) {
- data[i] = null; // discard
- }
- size = k;
- }
-
- @Override
- @Deprecated
- public void insert(Double distance, DBIDRef id) {
- final int kminus1 = k - 1;
- if(size < k || distance.doubleValue() <= data[kminus1].doubleDistance()) {
- // Ensure we have enough space.
- if(size > data.length) {
- grow();
- }
- insertionSort(new DoubleDistanceIntegerDBIDPair(distance.doubleValue(), id.internalGetIndex()));
- // Truncate if necessary:
- if(size > k && data[k].doubleDistance() > data[kminus1].doubleDistance()) {
- truncate();
- }
- }
- }
-
- @Override
- @Deprecated
- public void insert(DoubleDistance dist, DBIDRef id) {
- final int kminus1 = k - 1;
- if(size < k || dist.doubleValue() <= data[kminus1].doubleDistance()) {
- // Ensure we have enough space.
- if(size > data.length) {
- grow();
- }
- insertionSort(new DoubleDistanceIntegerDBIDPair(dist.doubleValue(), id.internalGetIndex()));
- // Truncate if necessary:
- if(size > k && data[k].doubleDistance() > data[kminus1].doubleDistance()) {
- truncate();
- }
- }
- }
-
- @Override
- public void insert(DoubleDistanceDBIDPair e) {
- final int kminus1 = k - 1;
- final double dist = e.doubleDistance();
- if(size < k || dist <= data[kminus1].doubleDistance()) {
- // Ensure we have enough space.
- if(size > data.length) {
- grow();
- }
- if(e instanceof DoubleDistanceIntegerDBIDPair) {
- insertionSort((DoubleDistanceIntegerDBIDPair) e);
- }
- else {
- insertionSort(new DoubleDistanceIntegerDBIDPair(dist, e.internalGetIndex()));
- }
- // Truncate if necessary:
- if(size > k && data[k].doubleDistance() > data[kminus1].doubleDistance()) {
- truncate();
- }
- }
- }
-
- /**
- * Perform insertion sort.
- *
- * @param obj Object to insert
- */
- private void insertionSort(DoubleDistanceIntegerDBIDPair obj) {
- // Insertion sort:
- int pos = size;
- while(pos > 0) {
- final int prev = pos - 1;
- DoubleDistanceIntegerDBIDPair pobj = data[prev];
- if(pobj.doubleDistance() <= obj.doubleDistance()) {
- break;
- }
- data[pos] = pobj;
- pos = prev;
- }
- data[pos] = obj;
- ++size;
- }
-
- private void grow() {
- final DoubleDistanceIntegerDBIDPair[] old = data;
- data = new DoubleDistanceIntegerDBIDPair[data.length + (data.length >> 1)];
- System.arraycopy(old, 0, data, 0, old.length);
- }
-
- @Override
- public DoubleDistanceIntegerDBIDPair poll() {
- assert (size > 0);
- return data[size--];
- }
-
- @Override
- public DoubleDistanceIntegerDBIDPair peek() {
- assert (size > 0);
- return data[size - 1];
- }
-
- @Override
- public DoubleDistanceKNNList toKNNList() {
- return this;
- }
-
- @Override
- public int getK() {
- return k;
- }
-
- @Override
- @Deprecated
- public DoubleDistance getKNNDistance() {
- if(size < k) {
- return DoubleDistance.INFINITE_DISTANCE;
- }
- return get(k - 1).getDistance();
- }
-
- @Override
- public double doubleKNNDistance() {
- if(size < k) {
- return Double.POSITIVE_INFINITY;
- }
- return get(k - 1).doubleDistance();
- }
-
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append("kNNList[");
- for(DoubleDistanceDBIDListIter iter = this.iter(); iter.valid();) {
- buf.append(iter.doubleDistance()).append(':').append(DBIDUtil.toString(iter));
- iter.advance();
- if(iter.valid()) {
- buf.append(',');
- }
- }
- buf.append(']');
- return buf.toString();
- }
-
- @Override
- public DoubleDistanceIntegerDBIDPair get(int index) {
- return data[index];
- }
-
- @Override
- public DoubleDistanceIntegerDBIDListIter iter() {
- return new Itr();
- }
-
- @Override
- public int size() {
- return size;
- }
-
- @Override
- public boolean contains(DBIDRef o) {
- for(DBIDIter iter = iter(); iter.valid(); iter.advance()) {
- if(DBIDUtil.equal(iter, o)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean isEmpty() {
- return size == 0;
- }
-
- /**
- * Iterator.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- private class Itr implements DoubleDistanceIntegerDBIDListIter {
- /**
- * Cursor position.
- */
- private int pos = 0;
-
- @Override
- public int internalGetIndex() {
- return get(pos).internalGetIndex();
- }
-
- @Override
- public boolean valid() {
- return pos < size;
- }
-
- @Override
- public void advance() {
- pos++;
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated use {@link #doubleDistance}!
- */
- @Override
- @Deprecated
- public DoubleDistance getDistance() {
- return get(pos).getDistance();
- }
-
- @Override
- public double doubleDistance() {
- return get(pos).doubleDistance();
- }
-
- @Override
- public DoubleDistanceIntegerDBIDPair getDistancePair() {
- return get(pos);
- }
-
- @Override
- public int getOffset() {
- return pos;
- }
-
- @Override
- public void advance(int count) {
- pos += count;
- }
-
- @Override
- public void retract() {
- --pos;
- }
-
- @Override
- public void seek(int off) {
- pos = off;
- }
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerArrayQuickSort.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerArrayQuickSort.java
deleted file mode 100644
index 8f1c58d6..00000000
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerArrayQuickSort.java
+++ /dev/null
@@ -1,181 +0,0 @@
-package de.lmu.ifi.dbs.elki.database.ids.integer;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- Ludwig-Maximilians-Universität München
- Lehr- und Forschungseinheit für Datenbanksysteme
- ELKI Development Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * Class to sort a double and an integer DBID array, using a quicksort with a
- * best of 5 heuristic.
- *
- * @author Erich Schubert
- */
-class DoubleIntegerArrayQuickSort {
- /**
- * Threshold for using insertion sort.
- */
- private static final int INSERTION_THRESHOLD = 22;
-
- /**
- * Sort the full array using the given comparator.
- *
- * @param keys Keys for sorting
- * @param values Values for sorting
- * @param len Length to sort.
- */
- public static void sort(double[] keys, int[] values, int len) {
- sort(keys, values, 0, len);
- }
-
- /**
- * Sort the array using the given comparator.
- *
- * @param keys Keys for sorting
- * @param values Values for sorting
- * @param start First index
- * @param end Last index (exclusive)
- */
- public static void sort(double[] keys, int[] values, int start, int end) {
- quickSort(keys, values, start, end);
- }
-
- /**
- * Actual recursive sort function.
- *
- * @param keys Keys for sorting
- * @param vals Values for sorting
- * @param start First index
- * @param end Last index (exclusive!)
- */
- private static void quickSort(double[] keys, int[] vals, final int start, final int end) {
- final int len = end - start;
- if (len < INSERTION_THRESHOLD) {
- // Classic insertion sort.
- for (int i = start + 1; i < end; i++) {
- for (int j = i; j > start; j--) {
- if (keys[j] < keys[j - 1]) {
- swap(keys, vals, j, j - 1);
- } else {
- break;
- }
- }
- }
- return;
- }
-
- // Choose pivots by looking at five candidates.
- final int seventh = (len >> 3) + (len >> 6) + 1;
- final int m3 = (start + end) >> 1; // middle
- final int m2 = m3 - seventh;
- final int m1 = m2 - seventh;
- final int m4 = m3 + seventh;
- final int m5 = m4 + seventh;
-
- // Mixture of insertion and merge sort:
- if (keys[m1] > keys[m2]) {
- swap(keys, vals, m1, m2);
- }
- if (keys[m3] > keys[m4]) {
- swap(keys, vals, m3, m4);
- }
- // Merge 1+2 and 3+4
- if (keys[m2] > keys[m4]) {
- swap(keys, vals, m2, m4);
- }
- if (keys[m1] > keys[m3]) {
- swap(keys, vals, m1, m3);
- }
- if (keys[m2] > keys[m3]) {
- swap(keys, vals, m2, m3);
- }
- // Insertion sort m5:
- if (keys[m4] > keys[m5]) {
- swap(keys, vals, m4, m5);
- if (keys[m3] > keys[m4]) {
- swap(keys, vals, m3, m4);
- if (keys[m2] > keys[m3]) {
- swap(keys, vals, m2, m3);
- if (keys[m1] > keys[m1]) {
- swap(keys, vals, m1, m2);
- }
- }
- }
- }
-
- // Move pivot to the front.
- double pivotkey = keys[m3];
- int pivotval = vals[m3];
- keys[m3] = keys[start];
- vals[m3] = vals[start];
-
- // The interval to pivotize
- int left = start + 1;
- int right = end - 1;
-
- // This is the classic QuickSort loop:
- while (true) {
- while (left <= right && keys[left] <= pivotkey) {
- left++;
- }
- while (left <= right && pivotkey <= keys[right]) {
- right--;
- }
- if (right <= left) {
- break;
- }
- swap(keys, vals, left, right);
- left++;
- right--;
- }
-
- // Move pivot back into the appropriate place
- keys[start] = keys[right];
- vals[start] = vals[right];
- keys[right] = pivotkey;
- vals[right] = pivotval;
-
- // Recursion:
- if (start + 1 < right) {
- quickSort(keys, vals, start, right);
- }
- if (right + 2 < end) {
- quickSort(keys, vals, right + 1, end);
- }
- }
-
- /**
- * Swap two entries.
- *
- * @param keys Keys
- * @param vals Values
- * @param j First index
- * @param i Second index
- */
- private static void swap(double[] keys, int[] vals, int j, int i) {
- double td = keys[j];
- keys[j] = keys[i];
- keys[i] = td;
- int ti = vals[j];
- vals[j] = vals[i];
- vals[i] = ti;
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDKNNHeap.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDKNNHeap.java
index 96babaa3..45a247f9 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDKNNHeap.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDKNNHeap.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -26,9 +26,8 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
import java.util.Arrays;
import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNHeap;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair;
+import de.lmu.ifi.dbs.elki.database.ids.KNNHeap;
import de.lmu.ifi.dbs.elki.utilities.datastructures.heap.DoubleIntegerMaxHeap;
/**
@@ -36,10 +35,10 @@ import de.lmu.ifi.dbs.elki.utilities.datastructures.heap.DoubleIntegerMaxHeap;
*
* @author Erich Schubert
*
- * @apiviz.has DoubleDistanceIntegerDBIDKNNList
+ * @apiviz.has DoubleIntegerDBIDKNNList
* @apiviz.composedOf DoubleIntegerMaxHeap
*/
-public class DoubleDistanceIntegerDBIDKNNHeap implements DoubleDistanceKNNHeap {
+class DoubleIntegerDBIDKNNHeap implements KNNHeap {
/**
* k for this heap.
*/
@@ -75,7 +74,7 @@ public class DoubleDistanceIntegerDBIDKNNHeap implements DoubleDistanceKNNHeap {
*
* @param k Size of knn.
*/
- public DoubleDistanceIntegerDBIDKNNHeap(int k) {
+ protected DoubleIntegerDBIDKNNHeap(int k) {
super();
this.k = k;
this.heap = new DoubleIntegerMaxHeap(k);
@@ -88,66 +87,11 @@ public class DoubleDistanceIntegerDBIDKNNHeap implements DoubleDistanceKNNHeap {
}
@Override
- @Deprecated
- public DoubleDistance getKNNDistance() {
- if(heap.size() < k) {
- return DoubleDistance.INFINITE_DISTANCE;
- }
- return new DoubleDistance(kdist);
- }
-
- @Override
- public double doubleKNNDistance() {
+ public double getKNNDistance() {
return kdist;
}
@Override
- @Deprecated
- public void insert(DoubleDistance distance, DBIDRef id) {
- final double dist = distance.doubleValue();
- final int iid = id.internalGetIndex();
- if(heap.size() < k) {
- heap.add(dist, iid);
- if(heap.size() >= k) {
- kdist = heap.peekKey();
- }
- return;
- }
- // Tied with top:
- if(dist >= kdist) {
- if(dist == kdist) {
- addToTies(iid);
- }
- return;
- }
- // Old top element: (kdist, previd)
- updateHeap(dist, iid);
- }
-
- @Override
- @Deprecated
- public void insert(Double distance, DBIDRef id) {
- final double dist = distance.doubleValue();
- final int iid = id.internalGetIndex();
- if(heap.size() < k) {
- heap.add(dist, iid);
- if(heap.size() >= k) {
- kdist = heap.peekKey();
- }
- return;
- }
- // Tied with top:
- if(dist >= kdist) {
- if(dist == kdist) {
- addToTies(iid);
- }
- return;
- }
- // Old top element: (kdist, previd)
- updateHeap(dist, iid);
- }
-
- @Override
public final double insert(final double distance, final DBIDRef id) {
final int iid = id.internalGetIndex();
if(heap.size() < k) {
@@ -170,8 +114,8 @@ public class DoubleDistanceIntegerDBIDKNNHeap implements DoubleDistanceKNNHeap {
}
@Override
- public void insert(final DoubleDistanceDBIDPair e) {
- final double distance = e.doubleDistance();
+ public void insert(final DoubleDBIDPair e) {
+ final double distance = e.doubleValue();
final int iid = e.internalGetIndex();
if(heap.size() < k) {
heap.add(distance, iid);
@@ -225,16 +169,12 @@ public class DoubleDistanceIntegerDBIDKNNHeap implements DoubleDistanceKNNHeap {
}
@Override
- public DoubleDistanceIntegerDBIDPair poll() {
- final DoubleDistanceIntegerDBIDPair ret;
+ public DoubleIntegerDBIDPair poll() {
if(numties > 0) {
- ret = new DoubleDistanceIntegerDBIDPair(kdist, ties[numties - 1]);
- --numties;
- }
- else {
- ret = new DoubleDistanceIntegerDBIDPair(heap.peekKey(), heap.peekValue());
- heap.poll();
+ return new DoubleIntegerDBIDPair(kdist, ties[--numties]);
}
+ final DoubleIntegerDBIDPair ret = new DoubleIntegerDBIDPair(heap.peekKey(), heap.peekValue());
+ heap.poll();
return ret;
}
@@ -251,11 +191,11 @@ public class DoubleDistanceIntegerDBIDKNNHeap implements DoubleDistanceKNNHeap {
}
@Override
- public DoubleDistanceIntegerDBIDPair peek() {
+ public DoubleIntegerDBIDPair peek() {
if(numties > 0) {
- return new DoubleDistanceIntegerDBIDPair(kdist, ties[numties - 1]);
+ return new DoubleIntegerDBIDPair(kdist, ties[numties - 1]);
}
- return new DoubleDistanceIntegerDBIDPair(heap.peekKey(), heap.peekValue());
+ return new DoubleIntegerDBIDPair(heap.peekKey(), heap.peekValue());
}
@Override
@@ -265,7 +205,7 @@ public class DoubleDistanceIntegerDBIDKNNHeap implements DoubleDistanceKNNHeap {
@Override
public boolean isEmpty() {
- return heap.size() == 0;
+ return heap.isEmpty();
}
@Override
@@ -275,9 +215,9 @@ public class DoubleDistanceIntegerDBIDKNNHeap implements DoubleDistanceKNNHeap {
}
@Override
- public DoubleDistanceIntegerDBIDKNNList toKNNList() {
+ public DoubleIntegerDBIDKNNList toKNNList() {
final int hsize = heap.size();
- DoubleDistanceIntegerDBIDKNNList ret = new DoubleDistanceIntegerDBIDKNNList(k, hsize + numties);
+ DoubleIntegerDBIDKNNList ret = new DoubleIntegerDBIDKNNList(k, hsize + numties);
// Add ties:
for(int i = 0; i < numties; i++) {
ret.dists[hsize + i] = kdist;
@@ -289,7 +229,6 @@ public class DoubleDistanceIntegerDBIDKNNHeap implements DoubleDistanceKNNHeap {
heap.poll();
}
ret.size = hsize + numties;
- ret.sort();
return ret;
}
@@ -299,12 +238,7 @@ public class DoubleDistanceIntegerDBIDKNNHeap implements DoubleDistanceKNNHeap {
* @return distance
*/
protected double peekDistance() {
- if(numties > 0) {
- return kdist;
- }
- else {
- return heap.peekKey();
- }
+ return (numties > 0) ? kdist : heap.peekKey();
}
/**
@@ -313,9 +247,6 @@ public class DoubleDistanceIntegerDBIDKNNHeap implements DoubleDistanceKNNHeap {
* @return internal id
*/
protected int peekInternalDBID() {
- if(numties > 0) {
- return ties[numties - 1];
- }
- return heap.peekValue();
+ return (numties > 0) ? ties[numties - 1] : heap.peekValue();
}
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDKNNList.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDKNNList.java
index f6515d88..b324955a 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDKNNList.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDKNNList.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -22,9 +22,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDListIter;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNList;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter;
/**
* kNN list, but without automatic sorting. Use with care, as others may expect
@@ -32,7 +30,7 @@ import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
*
* @author Erich Schubert
*/
-public class DoubleDistanceIntegerDBIDKNNList extends DoubleDistanceIntegerDBIDList implements DoubleDistanceKNNList {
+public class DoubleIntegerDBIDKNNList extends DoubleIntegerDBIDList implements IntegerDBIDKNNList {
/**
* The k value this list was generated for.
*/
@@ -41,7 +39,7 @@ public class DoubleDistanceIntegerDBIDKNNList extends DoubleDistanceIntegerDBIDL
/**
* Constructor.
*/
- public DoubleDistanceIntegerDBIDKNNList() {
+ public DoubleIntegerDBIDKNNList() {
super();
this.k = -1;
}
@@ -52,7 +50,7 @@ public class DoubleDistanceIntegerDBIDKNNList extends DoubleDistanceIntegerDBIDL
* @param k K parameter
* @param size Actual size
*/
- public DoubleDistanceIntegerDBIDKNNList(final int k, int size) {
+ public DoubleIntegerDBIDKNNList(final int k, int size) {
super(size);
this.k = k;
}
@@ -62,18 +60,8 @@ public class DoubleDistanceIntegerDBIDKNNList extends DoubleDistanceIntegerDBIDL
return k;
}
- /**
- * @deprecated Since you know this is a double distance heap, use
- * {@link #doubleKNNDistance()}
- */
- @Override
- @Deprecated
- public DoubleDistance getKNNDistance() {
- return new DoubleDistance(doubleKNNDistance());
- }
-
@Override
- public double doubleKNNDistance() {
+ public double getKNNDistance() {
return (size >= k) ? dists[k - 1] : Double.POSITIVE_INFINITY;
}
@@ -81,10 +69,10 @@ public class DoubleDistanceIntegerDBIDKNNList extends DoubleDistanceIntegerDBIDL
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("kNNList[");
- for (DoubleDistanceDBIDListIter iter = this.iter(); iter.valid();) {
- buf.append(iter.doubleDistance()).append(':').append(iter.internalGetIndex());
+ for(DoubleDBIDListIter iter = this.iter(); iter.valid();) {
+ buf.append(iter.doubleValue()).append(':').append(iter.internalGetIndex());
iter.advance();
- if (iter.valid()) {
+ if(iter.valid()) {
buf.append(',');
}
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDList.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDList.java
index 0db0204c..706938d5 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDList.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDList.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -24,10 +24,10 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
*/
import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDListIter;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.ModifiableDoubleDistanceDBIDList;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair;
+import de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList;
+import de.lmu.ifi.dbs.elki.utilities.datastructures.arrays.DoubleIntegerArrayQuickSort;
/**
* Class to store double distance, integer DBID results.
@@ -36,7 +36,7 @@ import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
*
* @apiviz.uses DoubleIntegerArrayQuickSort
*/
-public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDBIDList, IntegerDBIDs {
+class DoubleIntegerDBIDList implements ModifiableDoubleDBIDList, IntegerDBIDs {
/**
* Initial size allocation.
*/
@@ -70,7 +70,7 @@ public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDB
/**
* Constructor.
*/
- public DoubleDistanceIntegerDBIDList() {
+ protected DoubleIntegerDBIDList() {
dists = EMPTY_DISTS;
ids = EMPTY_IDS;
}
@@ -80,10 +80,10 @@ public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDB
*
* @param size Initial size
*/
- public DoubleDistanceIntegerDBIDList(int size) {
+ protected DoubleIntegerDBIDList(int size) {
this.dists = new double[size];
this.ids = new int[size];
- // This is default anyway: this.size = 0;
+ // This is default: this.size = 0;
}
@Override
@@ -94,8 +94,8 @@ public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDB
@Override
public boolean contains(DBIDRef o) {
final int q = o.internalGetIndex();
- for (int i = 0; i < size; i++) {
- if (q == ids[i]) {
+ for(int i = 0; i < size; i++) {
+ if(q == ids[i]) {
return true;
}
}
@@ -113,8 +113,8 @@ public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDB
}
@Override
- public DoubleDistanceIntegerDBIDPair get(int index) {
- return new DoubleDistanceIntegerDBIDPair(dists[index], ids[index]);
+ public DoubleIntegerDBIDPair get(int index) {
+ return new DoubleIntegerDBIDPair(dists[index], ids[index]);
}
/**
@@ -124,7 +124,7 @@ public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDB
* @param id Internal index
*/
protected void addInternal(double dist, int id) {
- if (size == dists.length) {
+ if(size == dists.length) {
grow();
}
dists[size] = dist;
@@ -136,7 +136,7 @@ public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDB
* Grow the data storage.
*/
protected void grow() {
- if (dists == EMPTY_DISTS) {
+ if(dists == EMPTY_DISTS) {
dists = new double[INITIAL_SIZE];
ids = new int[INITIAL_SIZE];
return;
@@ -152,19 +152,13 @@ public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDB
}
@Override
- @Deprecated
- public void add(DoubleDistance dist, DBIDRef id) {
- addInternal(dist.doubleValue(), id.internalGetIndex());
- }
-
- @Override
public void add(double dist, DBIDRef id) {
addInternal(dist, id.internalGetIndex());
}
@Override
- public void add(DoubleDistanceDBIDPair pair) {
- addInternal(pair.doubleDistance(), pair.internalGetIndex());
+ public void add(DoubleDBIDPair pair) {
+ addInternal(pair.doubleValue(), pair.internalGetIndex());
}
@Override
@@ -182,7 +176,7 @@ public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDB
* Reverse the list.
*/
protected void reverse() {
- for (int i = 0, j = size - 1; i < j; i++, j--) {
+ for(int i = 0, j = size - 1; i < j; i++, j--) {
double tmpd = dists[j];
dists[j] = dists[i];
dists[i] = tmpd;
@@ -198,7 +192,7 @@ public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDB
* @param newsize New size
*/
public void truncate(int newsize) {
- if (newsize < size) {
+ if(newsize < size) {
double[] odists = dists;
dists = new double[newsize];
System.arraycopy(odists, 0, dists, 0, newsize);
@@ -225,11 +219,11 @@ public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDB
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
- buf.append("DistanceDBIDList[");
- for (DoubleDistanceDBIDListIter iter = this.iter(); iter.valid();) {
- buf.append(iter.doubleDistance()).append(':').append(iter.internalGetIndex());
+ buf.append("DoubleDBIDList[");
+ for(DoubleDBIDListIter iter = this.iter(); iter.valid();) {
+ buf.append(iter.doubleValue()).append(':').append(iter.internalGetIndex());
iter.advance();
- if (iter.valid()) {
+ if(iter.valid()) {
buf.append(',');
}
}
@@ -244,11 +238,11 @@ public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDB
*
* @apiviz.exclude
*/
- private class Itr implements DoubleDistanceIntegerDBIDListIter {
+ private class Itr implements DoubleIntegerDBIDListIter, IntegerDBIDArrayIter {
/**
* Current offset.
*/
- int offset = 0;
+ int pos = 0;
/**
* Constructor.
@@ -259,53 +253,51 @@ public class DoubleDistanceIntegerDBIDList implements ModifiableDoubleDistanceDB
@Override
public boolean valid() {
- return offset < size;
+ return pos < size && pos >= 0;
}
@Override
- public void advance() {
- ++offset;
+ public Itr advance() {
+ ++pos;
+ return this;
}
@Override
public int getOffset() {
- return offset;
+ return pos;
}
@Override
- public void advance(int count) {
- offset += count;
+ public Itr advance(int count) {
+ pos += count;
+ return this;
}
@Override
- public void retract() {
- --offset;
+ public Itr retract() {
+ --pos;
+ return this;
}
@Override
- public void seek(int off) {
- offset = off;
+ public Itr seek(int off) {
+ pos = off;
+ return this;
}
@Override
public int internalGetIndex() {
- return ids[offset];
- }
-
- @Override
- public double doubleDistance() {
- return dists[offset];
+ return ids[pos];
}
@Override
- public DoubleDistanceDBIDPair getDistancePair() {
- return new DoubleDistanceIntegerDBIDPair(dists[offset], ids[offset]);
+ public double doubleValue() {
+ return dists[pos];
}
@Override
- @Deprecated
- public DoubleDistance getDistance() {
- return new DoubleDistance(dists[offset]);
+ public DoubleDBIDPair getPair() {
+ return new DoubleIntegerDBIDPair(dists[pos], ids[pos]);
}
}
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDListIter.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDListIter.java
index 0df81929..82d19990 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDListIter.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDListIter.java
@@ -1,10 +1,9 @@
package de.lmu.ifi.dbs.elki.database.ids.integer;
-
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -22,13 +21,14 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDListIter;
+
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter;
/**
- * Combination interface.
+ * Combination interface of the DoubleDBIDListIter with IntegerDBIDIter.
*
* @author Erich Schubert
*/
-public interface DoubleDistanceIntegerDBIDListIter extends DoubleDistanceDBIDListIter, IntegerDBIDArrayIter {
- // Yet another painful combination interface.
+public interface DoubleIntegerDBIDListIter extends DoubleDBIDListIter, IntegerDBIDIter {
+ // No additional methods.
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDSortedKNNList.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDListKNNHeap.java
index c4c60bc0..b2cd9d25 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDSortedKNNList.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDListKNNHeap.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,11 +23,10 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDListIter;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNHeap;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNList;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair;
+import de.lmu.ifi.dbs.elki.database.ids.KNNHeap;
+import de.lmu.ifi.dbs.elki.database.ids.KNNList;
/**
* Track the k nearest neighbors, with insertion sort to ensure the correct
@@ -35,13 +34,13 @@ import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
*
* @author Erich Schubert
*/
-public class DoubleDistanceIntegerDBIDSortedKNNList extends DoubleDistanceIntegerDBIDKNNList implements DoubleDistanceKNNHeap {
+class DoubleIntegerDBIDListKNNHeap extends DoubleIntegerDBIDKNNList implements KNNHeap {
/**
* Constructor.
*
* @param k K parameter
*/
- public DoubleDistanceIntegerDBIDSortedKNNList(int k) {
+ protected DoubleIntegerDBIDListKNNHeap(int k) {
super(k, k + 11);
}
@@ -107,36 +106,24 @@ public class DoubleDistanceIntegerDBIDSortedKNNList extends DoubleDistanceIntege
}
@Override
- @Deprecated
- public void insert(Double dist, DBIDRef id) {
- addInternal(dist.doubleValue(), id.internalGetIndex());
+ public void insert(DoubleDBIDPair e) {
+ addInternal(e.doubleValue(), e.internalGetIndex());
}
@Override
- public void insert(DoubleDistanceDBIDPair e) {
- addInternal(e.doubleDistance(), e.internalGetIndex());
- }
-
- @Override
- @Deprecated
- public void insert(DoubleDistance dist, DBIDRef id) {
- addInternal(dist.doubleValue(), id.internalGetIndex());
- }
-
- @Override
- public DoubleDistanceIntegerDBIDPair poll() {
+ public DoubleIntegerDBIDPair poll() {
final int last = size - 1;
- return new DoubleDistanceIntegerDBIDPair(dists[last], ids[last]);
+ return new DoubleIntegerDBIDPair(dists[last], ids[last]);
}
@Override
- public DoubleDistanceIntegerDBIDPair peek() {
+ public DoubleIntegerDBIDPair peek() {
final int last = size - 1;
- return new DoubleDistanceIntegerDBIDPair(dists[last], ids[last]);
+ return new DoubleIntegerDBIDPair(dists[last], ids[last]);
}
@Override
- public DoubleDistanceKNNList toKNNList() {
+ public KNNList toKNNList() {
return this;
}
@@ -144,8 +131,8 @@ public class DoubleDistanceIntegerDBIDSortedKNNList extends DoubleDistanceIntege
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("kNNListHeap[");
- for(DoubleDistanceDBIDListIter iter = this.iter(); iter.valid();) {
- buf.append(iter.doubleDistance()).append(':').append(iter.internalGetIndex());
+ for(DoubleDBIDListIter iter = this.iter(); iter.valid();) {
+ buf.append(iter.doubleValue()).append(':').append(iter.internalGetIndex());
iter.advance();
if(iter.valid()) {
buf.append(',');
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDoubleDBIDPair.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDPair.java
index b522ffb2..563fceb5 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDoubleDBIDPair.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDPair.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,7 +23,6 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.database.ids.DBID;
import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair;
/**
@@ -31,7 +30,7 @@ import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair;
*
* @author Erich Schubert
*/
-class IntegerDoubleDBIDPair implements DoubleDBIDPair, IntegerDBIDRef {
+class DoubleIntegerDBIDPair implements DoubleDBIDPair, IntegerDBIDRef {
/**
* The double value.
*/
@@ -48,7 +47,7 @@ class IntegerDoubleDBIDPair implements DoubleDBIDPair, IntegerDBIDRef {
* @param value Double value
* @param id DBID
*/
- protected IntegerDoubleDBIDPair(double value, int id) {
+ protected DoubleIntegerDBIDPair(double value, int id) {
super();
this.value = value;
this.id = id;
@@ -68,16 +67,4 @@ class IntegerDoubleDBIDPair implements DoubleDBIDPair, IntegerDBIDRef {
public double doubleValue() {
return value;
}
-
- @Override
- @Deprecated
- public Double getFirst() {
- return new Double(value);
- }
-
- @Override
- @Deprecated
- public DBID getSecond() {
- return new IntegerDBID(id);
- }
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDPairKNNListHeap.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDPairKNNListHeap.java
new file mode 100644
index 00000000..086b5f69
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDPairKNNListHeap.java
@@ -0,0 +1,286 @@
+package de.lmu.ifi.dbs.elki.database.ids.integer;
+
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2014
+ Ludwig-Maximilians-Universität München
+ Lehr- und Forschungseinheit für Datenbanksysteme
+ ELKI Development Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
+import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
+import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair;
+import de.lmu.ifi.dbs.elki.database.ids.KNNHeap;
+import de.lmu.ifi.dbs.elki.database.ids.KNNList;
+
+/**
+ * KNN Heap implemented using a list of DoubleInt pair objects.
+ *
+ * Currently unused, needs benchmarking.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.composedOf DoubleIntegerDBIDPair
+ */
+class DoubleIntegerDBIDPairKNNListHeap implements IntegerDBIDKNNList, KNNHeap {
+ /**
+ * The value of k this was materialized for.
+ */
+ private final int k;
+
+ /**
+ * The actual data array.
+ */
+ private DoubleIntegerDBIDPair[] data;
+
+ /**
+ * Current size
+ */
+ private int size;
+
+ /**
+ * Constructor.
+ *
+ * @param k K parameter
+ */
+ protected DoubleIntegerDBIDPairKNNListHeap(int k) {
+ super();
+ this.data = new DoubleIntegerDBIDPair[k + 5];
+ this.k = k;
+ this.size = 0;
+ }
+
+ @Override
+ public void clear() {
+ for(int i = 0; i < size; i++) {
+ data[i] = null; // discard
+ }
+ size = 0;
+ }
+
+ @Override
+ public double insert(double distance, DBIDRef id) {
+ final int kminus1 = k - 1;
+ if(size < k || distance <= data[kminus1].doubleValue()) {
+ // Ensure we have enough space.
+ if(size > data.length) {
+ grow();
+ }
+ insertionSort(new DoubleIntegerDBIDPair(distance, id.internalGetIndex()));
+ // Truncate if necessary:
+ if(size > k && data[k].doubleValue() > data[kminus1].doubleValue()) {
+ truncate();
+ }
+ }
+ return (size < k) ? Double.POSITIVE_INFINITY : get(kminus1).doubleValue();
+ }
+
+ private void truncate() {
+ for(int i = k; i < size; i++) {
+ data[i] = null; // discard
+ }
+ size = k;
+ }
+
+ @Override
+ public void insert(DoubleDBIDPair e) {
+ final int kminus1 = k - 1;
+ final double dist = e.doubleValue();
+ if(size < k || dist <= data[kminus1].doubleValue()) {
+ // Ensure we have enough space.
+ if(size > data.length) {
+ grow();
+ }
+ if(e instanceof DoubleIntegerDBIDPair) {
+ insertionSort((DoubleIntegerDBIDPair) e);
+ }
+ else {
+ insertionSort(new DoubleIntegerDBIDPair(dist, e.internalGetIndex()));
+ }
+ // Truncate if necessary:
+ if(size > k && data[k].doubleValue() > data[kminus1].doubleValue()) {
+ truncate();
+ }
+ }
+ }
+
+ /**
+ * Perform insertion sort.
+ *
+ * @param obj Object to insert
+ */
+ private void insertionSort(DoubleIntegerDBIDPair obj) {
+ // Insertion sort:
+ int pos = size;
+ while(pos > 0) {
+ final int prev = pos - 1;
+ DoubleIntegerDBIDPair pobj = data[prev];
+ if(pobj.doubleValue() <= obj.doubleValue()) {
+ break;
+ }
+ data[pos] = pobj;
+ pos = prev;
+ }
+ data[pos] = obj;
+ ++size;
+ }
+
+ private void grow() {
+ final DoubleIntegerDBIDPair[] old = data;
+ data = new DoubleIntegerDBIDPair[data.length + (data.length >> 1)];
+ System.arraycopy(old, 0, data, 0, old.length);
+ }
+
+ @Override
+ public DoubleIntegerDBIDPair poll() {
+ assert (size > 0);
+ return data[size--];
+ }
+
+ @Override
+ public DoubleIntegerDBIDPair peek() {
+ assert (size > 0);
+ return data[size - 1];
+ }
+
+ @Override
+ public KNNList toKNNList() {
+ return this;
+ }
+
+ @Override
+ public int getK() {
+ return k;
+ }
+
+ @Override
+ public double getKNNDistance() {
+ return (size >= k) ? get(k - 1).doubleValue() : Double.POSITIVE_INFINITY;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buf = new StringBuilder();
+ buf.append("kNNList[");
+ for(DoubleDBIDListIter iter = this.iter(); iter.valid();) {
+ buf.append(iter.doubleValue()).append(':').append(DBIDUtil.toString(iter));
+ iter.advance();
+ if(iter.valid()) {
+ buf.append(',');
+ }
+ }
+ buf.append(']');
+ return buf.toString();
+ }
+
+ @Override
+ public DoubleIntegerDBIDPair get(int index) {
+ return data[index];
+ }
+
+ @Override
+ public Itr iter() {
+ return new Itr();
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public boolean contains(DBIDRef o) {
+ for(DBIDIter iter = iter(); iter.valid(); iter.advance()) {
+ if(DBIDUtil.equal(iter, o)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return size == 0;
+ }
+
+ /**
+ * Iterator.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.exclude
+ */
+ private class Itr implements DoubleIntegerDBIDListIter, IntegerDBIDArrayIter {
+ /**
+ * Cursor position.
+ */
+ private int pos = 0;
+
+ @Override
+ public int internalGetIndex() {
+ return get(pos).internalGetIndex();
+ }
+
+ @Override
+ public boolean valid() {
+ return pos < size && pos >= 0;
+ }
+
+ @Override
+ public Itr advance() {
+ pos++;
+ return this;
+ }
+
+ @Override
+ public double doubleValue() {
+ return get(pos).doubleValue();
+ }
+
+ @Override
+ public DoubleIntegerDBIDPair getPair() {
+ return get(pos);
+ }
+
+ @Override
+ public int getOffset() {
+ return pos;
+ }
+
+ @Override
+ public Itr advance(int count) {
+ pos += count;
+ return this;
+ }
+
+ @Override
+ public Itr retract() {
+ --pos;
+ return this;
+ }
+
+ @Override
+ public Itr seek(int off) {
+ pos = off;
+ return this;
+ }
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDPairList.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDPairList.java
index 5b33d3f9..bee9d47d 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleDistanceIntegerDBIDPairList.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/DoubleIntegerDBIDPairList.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -25,18 +25,18 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
import java.util.Arrays;
import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDListIter;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.ModifiableDoubleDistanceDBIDList;
-import de.lmu.ifi.dbs.elki.distance.distanceresultlist.DistanceDBIDResultUtil;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair;
+import de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList;
/**
* Class to store double distance, integer DBID results.
*
+ * Currently unused. Needs benchmarking.
+ *
* @author Erich Schubert
*/
-public class DoubleDistanceIntegerDBIDPairList implements ModifiableDoubleDistanceDBIDList, IntegerDBIDs {
+class DoubleIntegerDBIDPairList implements ModifiableDoubleDBIDList, IntegerDBIDs {
/**
* The size
*/
@@ -45,14 +45,14 @@ public class DoubleDistanceIntegerDBIDPairList implements ModifiableDoubleDistan
/**
* Distance values
*/
- DoubleDistanceIntegerDBIDPair[] data;
+ DoubleIntegerDBIDPair[] data;
/**
* Constructor.
*/
- public DoubleDistanceIntegerDBIDPairList() {
+ protected DoubleIntegerDBIDPairList() {
super();
- this.data = new DoubleDistanceIntegerDBIDPair[21];
+ this.data = new DoubleIntegerDBIDPair[21];
}
/**
@@ -60,24 +60,24 @@ public class DoubleDistanceIntegerDBIDPairList implements ModifiableDoubleDistan
*
* @param size Initial size
*/
- public DoubleDistanceIntegerDBIDPairList(int size) {
+ protected DoubleIntegerDBIDPairList(int size) {
super();
- if (size > 0) {
+ if(size > 0) {
size = 21;
}
- this.data = new DoubleDistanceIntegerDBIDPair[size];
+ this.data = new DoubleIntegerDBIDPair[size];
}
@Override
- public DoubleDistanceIntegerDBIDListIter iter() {
+ public Itr iter() {
return new Itr();
}
@Override
public boolean contains(DBIDRef o) {
final int q = o.internalGetIndex();
- for (int i = 0; i < size; i++) {
- if (q == data[i].internalGetIndex()) {
+ for(int i = 0; i < size; i++) {
+ if(q == data[i].internalGetIndex()) {
return true;
}
}
@@ -95,7 +95,7 @@ public class DoubleDistanceIntegerDBIDPairList implements ModifiableDoubleDistan
}
@Override
- public DoubleDistanceIntegerDBIDPair get(int index) {
+ public DoubleIntegerDBIDPair get(int index) {
return data[index];
}
@@ -104,32 +104,27 @@ public class DoubleDistanceIntegerDBIDPairList implements ModifiableDoubleDistan
*
* @param pair entry
*/
- protected void addInternal(DoubleDistanceIntegerDBIDPair pair) {
- if (size == data.length) {
- DoubleDistanceIntegerDBIDPair[] old = data;
- data = new DoubleDistanceIntegerDBIDPair[(data.length << 1) + 1];
+ protected void addInternal(DoubleIntegerDBIDPair pair) {
+ if(size == data.length) {
+ DoubleIntegerDBIDPair[] old = data;
+ data = new DoubleIntegerDBIDPair[(data.length << 1) + 1];
System.arraycopy(old, 0, data, 0, old.length);
}
data[size++] = pair;
}
@Override
- @Deprecated
- public void add(DoubleDistance dist, DBIDRef id) {
- add(dist.doubleValue(), id);
- }
-
- @Override
public void add(double dist, DBIDRef id) {
- addInternal(new DoubleDistanceIntegerDBIDPair(dist, id.internalGetIndex()));
+ addInternal(new DoubleIntegerDBIDPair(dist, id.internalGetIndex()));
}
@Override
- public void add(DoubleDistanceDBIDPair pair) {
- if (pair instanceof DoubleDistanceIntegerDBIDPair) {
- addInternal((DoubleDistanceIntegerDBIDPair) pair);
- } else {
- addInternal(new DoubleDistanceIntegerDBIDPair(pair.doubleDistance(), pair.internalGetIndex()));
+ public void add(DoubleDBIDPair pair) {
+ if(pair instanceof DoubleIntegerDBIDPair) {
+ addInternal((DoubleIntegerDBIDPair) pair);
+ }
+ else {
+ addInternal(new DoubleIntegerDBIDPair(pair.doubleValue(), pair.internalGetIndex()));
}
}
@@ -141,15 +136,15 @@ public class DoubleDistanceIntegerDBIDPairList implements ModifiableDoubleDistan
@Override
public void sort() {
- Arrays.sort(data, 0, size, DistanceDBIDResultUtil.distanceComparator());
+ Arrays.sort(data, 0, size);
}
/**
* Reverse the list.
*/
protected void reverse() {
- for (int i = 0, j = size - 1; i < j; i++, j--) {
- DoubleDistanceIntegerDBIDPair tmpd = data[j];
+ for(int i = 0, j = size - 1; i < j; i++, j--) {
+ DoubleIntegerDBIDPair tmpd = data[j];
data[j] = data[i];
data[i] = tmpd;
}
@@ -159,10 +154,10 @@ public class DoubleDistanceIntegerDBIDPairList implements ModifiableDoubleDistan
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("kNNList[");
- for (DoubleDistanceDBIDListIter iter = this.iter(); iter.valid();) {
- buf.append(iter.doubleDistance()).append(':').append(iter.internalGetIndex());
+ for(DoubleDBIDListIter iter = this.iter(); iter.valid();) {
+ buf.append(iter.doubleValue()).append(':').append(iter.internalGetIndex());
iter.advance();
- if (iter.valid()) {
+ if(iter.valid()) {
buf.append(',');
}
}
@@ -177,58 +172,56 @@ public class DoubleDistanceIntegerDBIDPairList implements ModifiableDoubleDistan
*
* @apiviz.exclude
*/
- private class Itr implements DoubleDistanceIntegerDBIDListIter {
- int offset = 0;
+ private class Itr implements DoubleDBIDListIter, IntegerDBIDArrayIter {
+ int pos = 0;
@Override
public boolean valid() {
- return offset < size;
+ return pos < size && pos >= 0;
}
@Override
- public void advance() {
- ++offset;
+ public Itr advance() {
+ ++pos;
+ return this;
}
@Override
public int getOffset() {
- return offset;
+ return pos;
}
@Override
- public void advance(int count) {
- offset += count;
+ public Itr advance(int count) {
+ pos += count;
+ return this;
}
@Override
- public void retract() {
- offset--;
+ public Itr retract() {
+ pos--;
+ return this;
}
@Override
- public void seek(int off) {
- offset = off;
+ public Itr seek(int off) {
+ pos = off;
+ return this;
}
@Override
public int internalGetIndex() {
- return data[offset].internalGetIndex();
- }
-
- @Override
- public double doubleDistance() {
- return data[offset].doubleDistance();
+ return data[pos].internalGetIndex();
}
@Override
- public DoubleDistanceDBIDPair getDistancePair() {
- return data[offset];
+ public double doubleValue() {
+ return data[pos].doubleValue();
}
@Override
- @Deprecated
- public DoubleDistance getDistance() {
- return new DoubleDistance(data[offset].doubleDistance());
+ public DoubleDBIDPair getPair() {
+ return data[pos];
}
}
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerArrayDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerArrayDBIDs.java
index 286bedf9..99519ce8 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerArrayDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerArrayDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerArrayStaticDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerArrayStaticDBIDs.java
index 9e18631b..8e82ba3f 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerArrayStaticDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerArrayStaticDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -30,7 +30,7 @@ import de.lmu.ifi.dbs.elki.database.ids.ArrayStaticDBIDs;
*
* @author Erich Schubert
*/
-public interface IntegerArrayStaticDBIDs extends ArrayStaticDBIDs, IntegerArrayDBIDs {
+interface IntegerArrayStaticDBIDs extends ArrayStaticDBIDs, IntegerArrayDBIDs {
@Override
IntegerDBIDArrayIter iter();
} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBID.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBID.java
index 6b7ec5ac..572ec5d9 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBID.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBID.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -32,9 +32,9 @@ import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
import de.lmu.ifi.dbs.elki.database.ids.DBIDVar;
import de.lmu.ifi.dbs.elki.logging.LoggingUtil;
-import de.lmu.ifi.dbs.elki.persistent.ByteArrayUtil;
-import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer;
-import de.lmu.ifi.dbs.elki.persistent.FixedSizeByteBufferSerializer;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteArrayUtil;
+import de.lmu.ifi.dbs.elki.utilities.io.ByteBufferSerializer;
+import de.lmu.ifi.dbs.elki.utilities.io.FixedSizeByteBufferSerializer;
/**
* Database ID object.
@@ -185,23 +185,27 @@ final class IntegerDBID implements DBID, IntegerDBIDRef {
int pos = 0;
@Override
- public void advance() {
+ public Itr advance() {
pos++;
+ return this;
}
@Override
- public void advance(int count) {
+ public Itr advance(int count) {
pos += count;
+ return this;
}
@Override
- public void retract() {
+ public Itr retract() {
pos--;
+ return this;
}
@Override
- public void seek(int off) {
+ public Itr seek(int off) {
pos = off;
+ return this;
}
@Override
@@ -248,7 +252,7 @@ final class IntegerDBID implements DBID, IntegerDBIDRef {
/**
* Constructor. Protected: use static instance!
*/
- protected DynamicSerializer() {
+ public DynamicSerializer() {
super();
}
@@ -277,7 +281,7 @@ final class IntegerDBID implements DBID, IntegerDBIDRef {
/**
* Constructor. Protected: use static instance!
*/
- protected StaticSerializer() {
+ public StaticSerializer() {
super();
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayIter.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayIter.java
index c604ac71..30255d87 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayIter.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayIter.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -29,6 +29,6 @@ import de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter;
*
* @author Erich Schubert
*/
-public interface IntegerDBIDArrayIter extends IntegerDBIDIter, DBIDArrayIter {
+interface IntegerDBIDArrayIter extends IntegerDBIDIter, DBIDArrayIter {
// Empty
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayMIter.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayMIter.java
index dcead6bd..750f7644 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayMIter.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayMIter.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -29,6 +29,6 @@ import de.lmu.ifi.dbs.elki.database.ids.DBIDArrayMIter;
*
* @author Erich Schubert
*/
-public interface IntegerDBIDArrayMIter extends IntegerDBIDArrayIter, IntegerDBIDMIter, DBIDArrayMIter {
+interface IntegerDBIDArrayMIter extends IntegerDBIDArrayIter, IntegerDBIDMIter, DBIDArrayMIter {
// Empty
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayQuickSort.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayQuickSort.java
index d6cadf60..03fcb16b 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayQuickSort.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDArrayQuickSort.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDIter.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDIter.java
index 721e6e4e..893649fa 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDIter.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDIter.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -31,6 +31,6 @@ import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
*
* @apiviz.landmark
*/
-public interface IntegerDBIDIter extends IntegerDBIDRef, DBIDIter {
+interface IntegerDBIDIter extends IntegerDBIDRef, DBIDIter {
// Empty
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDList.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDKNNList.java
index 85182313..d493271e 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/distance/DoubleDistanceDBIDList.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDKNNList.java
@@ -1,10 +1,9 @@
-package de.lmu.ifi.dbs.elki.database.ids.distance;
-
+package de.lmu.ifi.dbs.elki.database.ids.integer;
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,17 +22,18 @@ package de.lmu.ifi.dbs.elki.database.ids.distance;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDList;
+import de.lmu.ifi.dbs.elki.database.ids.KNNList;
/**
- * An object containing Double-DBID-Pairs.
+ * Combination interface for KNNList and IntegerDBIDs.
*
* @author Erich Schubert
*/
-public interface DoubleDistanceDBIDList extends DistanceDBIDList<DoubleDistance> {
+public interface IntegerDBIDKNNList extends KNNList, DoubleDBIDList, IntegerDBIDs {
@Override
- DoubleDistanceDBIDListIter iter();
-
+ DoubleIntegerDBIDListIter iter();
+
@Override
- DoubleDistanceDBIDPair get(int off);
+ public DoubleIntegerDBIDPair get(int index);
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceKNNSubList.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDKNNSubList.java
index c2854a54..bd53f7e1 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/generic/DoubleDistanceKNNSubList.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDKNNSubList.java
@@ -1,10 +1,10 @@
-package de.lmu.ifi.dbs.elki.database.ids.generic;
+package de.lmu.ifi.dbs.elki.database.ids.integer;
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -25,19 +25,14 @@ package de.lmu.ifi.dbs.elki.database.ids.generic;
import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDPair;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceDBIDListIter;
-import de.lmu.ifi.dbs.elki.database.ids.distance.DoubleDistanceKNNList;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
+import de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair;
/**
* Sublist of an existing result to contain only the first k elements.
*
- * TOOD: can be optimized slightly better.
- *
* @author Erich Schubert
*/
-public class DoubleDistanceKNNSubList implements DoubleDistanceKNNList {
+public class IntegerDBIDKNNSubList implements IntegerDBIDKNNList {
/**
* Parameter k.
*/
@@ -51,7 +46,7 @@ public class DoubleDistanceKNNSubList implements DoubleDistanceKNNList {
/**
* Wrapped inner result.
*/
- private final DoubleDistanceKNNList inner;
+ private final IntegerDBIDKNNList inner;
/**
* Constructor.
@@ -59,21 +54,23 @@ public class DoubleDistanceKNNSubList implements DoubleDistanceKNNList {
* @param inner Inner instance
* @param k k value
*/
- public DoubleDistanceKNNSubList(DoubleDistanceKNNList inner, int k) {
+ public IntegerDBIDKNNSubList(IntegerDBIDKNNList inner, int k) {
this.inner = inner;
this.k = k;
// Compute list size
- {
- DoubleDistanceDBIDPair dist = inner.get(k);
+ if(k < inner.getK()) {
+ DoubleIntegerDBIDListIter iter = inner.iter();
+ final double kdist = iter.seek(k - 1).doubleValue();
+ // Add all values tied:
int i = k;
- while (i + 1 < inner.size()) {
- if (dist.compareByDistance(inner.get(i + 1)) < 0) {
- break;
- }
+ for(iter.advance(); iter.valid() && iter.doubleValue() <= kdist; iter.advance()) {
i++;
}
size = i;
}
+ else {
+ size = inner.size();
+ }
}
@Override
@@ -82,31 +79,25 @@ public class DoubleDistanceKNNSubList implements DoubleDistanceKNNList {
}
@Override
- public DoubleDistanceDBIDPair get(int index) {
+ public DoubleIntegerDBIDPair get(int index) {
assert (index < size) : "Access beyond design size of list.";
return inner.get(index);
}
@Override
- @Deprecated
- public DoubleDistance getKNNDistance() {
- return inner.get(k).getDistance();
- }
-
- @Override
- public double doubleKNNDistance() {
- return inner.get(k).doubleDistance();
+ public double getKNNDistance() {
+ return inner.get(k).doubleValue();
}
@Override
- public DoubleDistanceDBIDListIter iter() {
+ public DoubleIntegerDBIDListIter iter() {
return new Itr();
}
@Override
public boolean contains(DBIDRef o) {
- for (DBIDIter iter = iter(); iter.valid(); iter.advance()) {
- if (DBIDUtil.equal(iter, o)) {
+ for(DBIDIter iter = iter(); iter.valid(); iter.advance()) {
+ if(DBIDUtil.equal(iter, o)) {
return true;
}
}
@@ -130,7 +121,7 @@ public class DoubleDistanceKNNSubList implements DoubleDistanceKNNList {
*
* @apiviz.exclude
*/
- private class Itr implements DoubleDistanceDBIDListIter {
+ private class Itr implements DoubleIntegerDBIDListIter {
/**
* Current position.
*/
@@ -138,27 +129,22 @@ public class DoubleDistanceKNNSubList implements DoubleDistanceKNNList {
@Override
public boolean valid() {
- return pos < size;
+ return pos < size && pos >= 0;
}
@Override
- public void advance() {
+ public Itr advance() {
pos++;
+ return this;
}
@Override
- @Deprecated
- public DoubleDistance getDistance() {
- return inner.get(pos).getDistance();
- }
-
- @Override
- public double doubleDistance() {
- return inner.get(pos).doubleDistance();
+ public double doubleValue() {
+ return inner.get(pos).doubleValue();
}
@Override
- public DoubleDistanceDBIDPair getDistancePair() {
+ public DoubleDBIDPair getPair() {
return inner.get(pos);
}
@@ -173,18 +159,21 @@ public class DoubleDistanceKNNSubList implements DoubleDistanceKNNList {
}
@Override
- public void advance(int count) {
+ public Itr advance(int count) {
pos += count;
+ return this;
}
@Override
- public void retract() {
+ public Itr retract() {
--pos;
+ return this;
}
@Override
- public void seek(int off) {
+ public Itr seek(int off) {
pos = off;
+ return this;
}
}
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDMIter.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDMIter.java
index c0291d5b..067a257b 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDMIter.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDMIter.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -29,6 +29,6 @@ import de.lmu.ifi.dbs.elki.database.ids.DBIDMIter;
*
* @author Erich Schubert
*/
-public interface IntegerDBIDMIter extends DBIDMIter, IntegerDBIDIter {
+interface IntegerDBIDMIter extends DBIDMIter, IntegerDBIDIter {
// Empty.
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDPair.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDPair.java
index 12e9b685..9c691bc9 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDPair.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDPair.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,14 +23,16 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
import de.lmu.ifi.dbs.elki.database.ids.DBIDPair;
+import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
/**
* DBID pair using two ints for storage.
*
* @author Erich Schubert
*/
-public class IntegerDBIDPair implements DBIDPair {
+class IntegerDBIDPair implements DBIDPair, IntegerDBIDs {
/**
* First value in pair
*/
@@ -47,7 +49,7 @@ public class IntegerDBIDPair implements DBIDPair {
* @param first first parameter
* @param second second parameter
*/
- public IntegerDBIDPair(int first, int second) {
+ protected IntegerDBIDPair(int first, int second) {
this.first = first;
this.second = second;
}
@@ -60,36 +62,18 @@ public class IntegerDBIDPair implements DBIDPair {
return "Pair(" + first + ", " + second + ")";
}
- /**
- * Getter for first
- *
- * @return first element in pair
- */
+ @Deprecated
@Override
public final IntegerDBID getFirst() {
return new IntegerDBID(first);
}
- /**
- * Getter for second element in pair
- *
- * @return second element in pair
- */
+ @Deprecated
@Override
public final IntegerDBID getSecond() {
return new IntegerDBID(second);
}
- /**
- * Simple equals statement.
- *
- * This Pair equals another Object if they are identical or if the other
- * Object is also a Pair and the {@link #first} and {@link #second} element of
- * this Pair equal the {@link #first} and {@link #second} element,
- * respectively, of the other Pair.
- *
- * @param obj Object to compare to
- */
@Override
public boolean equals(Object obj) {
if(this == obj) {
@@ -118,4 +102,68 @@ public class IntegerDBIDPair implements DBIDPair {
result = prime * result + second;
return (int) result;
}
+
+ @Override
+ public int size() {
+ return 2;
+ }
+
+ @Override
+ public boolean contains(DBIDRef o) {
+ final int i = o.internalGetIndex();
+ return (i == first) || (i == second);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return false;
+ }
+
+ @Override
+ public IntegerDBIDIter iter() {
+ return new Itr(first, second);
+ }
+
+ /**
+ * Iterator.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.exclude
+ */
+ private static class Itr implements IntegerDBIDIter {
+ /**
+ * State
+ */
+ int first, second, pos;
+
+ /**
+ * Constructor.
+ *
+ * @param first First ID
+ * @param second Second ID
+ */
+ public Itr(int first, int second) {
+ super();
+ this.first = first;
+ this.second = second;
+ this.pos = 0;
+ }
+
+ @Override
+ public boolean valid() {
+ return pos < 2;
+ }
+
+ @Override
+ public DBIDIter advance() {
+ ++pos;
+ return this;
+ }
+
+ @Override
+ public int internalGetIndex() {
+ return (pos == 0) ? first : second;
+ }
+ }
} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDRange.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDRange.java
index e418db5f..4b8aed26 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDRange.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDRange.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -184,23 +184,27 @@ final class IntegerDBIDRange implements IntegerDBIDs, DBIDRange, SetDBIDs {
}
@Override
- public void advance() {
+ public Itr advance() {
++pos;
+ return this;
}
@Override
- public void advance(int count) {
+ public Itr advance(int count) {
pos += count;
+ return this;
}
@Override
- public void retract() {
+ public Itr retract() {
--pos;
+ return this;
}
@Override
- public void seek(int off) {
+ public Itr seek(int off) {
pos = off;
+ return this;
}
@Override
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDRef.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDRef.java
index 0e1e82a9..ddd56209 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDRef.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDRef.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDVar.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDVar.java
index 9120c0d7..c5dfb9b6 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDVar.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDVar.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -25,6 +25,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
import de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs;
import de.lmu.ifi.dbs.elki.database.ids.DBID;
+import de.lmu.ifi.dbs.elki.database.ids.DBIDPair;
import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
import de.lmu.ifi.dbs.elki.database.ids.DBIDVar;
@@ -49,7 +50,7 @@ class IntegerDBIDVar implements DBIDVar, IntegerDBIDs {
* Constructor.
*/
protected IntegerDBIDVar() {
- this.id = -1;
+ this.id = Integer.MIN_VALUE;
}
/**
@@ -81,8 +82,21 @@ class IntegerDBIDVar implements DBIDVar, IntegerDBIDs {
}
@Override
+ public void setFirst(DBIDPair pair) {
+ assert pair instanceof IntegerDBIDPair;
+ id = ((IntegerDBIDPair) pair).first;
+ }
+
+ @Override
+ public void setSecond(DBIDPair pair) {
+ assert pair instanceof IntegerDBIDPair;
+ id = ((IntegerDBIDPair) pair).second;
+ }
+
+ @Override
+ @Deprecated
public DBID get(int i) {
- if (i != 0) {
+ if(i != 0) {
throw new ArrayIndexOutOfBoundsException();
}
return new IntegerDBID(i);
@@ -90,12 +104,22 @@ class IntegerDBIDVar implements DBIDVar, IntegerDBIDs {
@Override
public int size() {
- return 1;
+ return id < 0 ? 0 : 1;
}
@Override
public boolean isEmpty() {
- return false;
+ return id < 0;
+ }
+
+ @Override
+ public void unset() {
+ id = Integer.MIN_VALUE;
+ }
+
+ @Override
+ public boolean isSet() {
+ return id > 0;
}
@Override
@@ -111,9 +135,10 @@ class IntegerDBIDVar implements DBIDVar, IntegerDBIDs {
@Override
public void assignVar(int i, DBIDVar var) {
- if (var instanceof IntegerDBIDVar) {
+ if(var instanceof IntegerDBIDVar) {
((IntegerDBIDVar) var).internalSetIndex(i);
- } else {
+ }
+ else {
// Much less efficient:
var.set(get(i));
}
@@ -121,9 +146,10 @@ class IntegerDBIDVar implements DBIDVar, IntegerDBIDs {
@Override
public ArrayDBIDs slice(int begin, int end) {
- if (begin == 0 && end == 1) {
+ if(begin == 0 && end == 1) {
return this;
- } else {
+ }
+ else {
return DBIDUtil.EMPTYDBIDS;
}
}
@@ -150,56 +176,60 @@ class IntegerDBIDVar implements DBIDVar, IntegerDBIDs {
* Iterator position: We use an integer so we can support retract().
*/
int pos = 0;
-
+
@Override
- public void advance() {
+ public Itr advance() {
pos++;
+ return this;
}
-
+
@Override
- public void advance(int count) {
+ public Itr advance(int count) {
pos += count;
+ return this;
}
-
+
@Override
- public void retract() {
+ public Itr retract() {
pos--;
+ return this;
}
-
+
@Override
- public void seek(int off) {
+ public Itr seek(int off) {
pos = off;
+ return this;
}
-
+
@Override
public int getOffset() {
return pos;
}
-
+
@Override
public int internalGetIndex() {
return IntegerDBIDVar.this.id;
}
-
+
@Override
public boolean valid() {
return (pos == 0);
}
-
+
@Override
public int hashCode() {
// Override, because we also are overriding equals.
return super.hashCode();
}
-
+
@Override
public boolean equals(Object other) {
- if (other instanceof DBID) {
+ if(other instanceof DBID) {
LoggingUtil.warning("Programming error detected: DBIDItr.equals(DBID). Use sameDBID()!", new Throwable());
}
return super.equals(other);
}
-
+
@Override
public String toString() {
return Integer.toString(internalGetIndex());
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDs.java
index 14faa72a..1abaa423 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/IntegerDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/ReusingDBIDFactory.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/ReusingDBIDFactory.java
index ebb36f22..da730f4f 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/ReusingDBIDFactory.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/ReusingDBIDFactory.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/SimpleDBIDFactory.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/SimpleDBIDFactory.java
index c3abd43a..33ddd240 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/SimpleDBIDFactory.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/SimpleDBIDFactory.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -48,7 +48,7 @@ public class SimpleDBIDFactory extends AbstractIntegerDBIDFactory {
* The starting point for static DBID range allocations.
*/
int rangestart = 0;
-
+
/**
* Constructor.
*/
@@ -81,6 +81,16 @@ public class SimpleDBIDFactory extends AbstractIntegerDBIDFactory {
}
@Override
+ public DBIDRange generateStaticDBIDRange(int begin, int size) {
+ if(begin + size >= Integer.MAX_VALUE) {
+ throw new AbortException("DBID range allocation error - too many objects allocated!");
+ }
+ DBIDRange alloc = new IntegerDBIDRange(begin, size);
+ rangestart = Math.max(rangestart, begin + size);
+ return alloc;
+ }
+
+ @Override
public void deallocateDBIDRange(DBIDRange range) {
// ignore.
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/TrivialDBIDFactory.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/TrivialDBIDFactory.java
index 577c29ac..cc5f6add 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/TrivialDBIDFactory.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/TrivialDBIDFactory.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -55,7 +55,7 @@ final public class TrivialDBIDFactory extends AbstractIntegerDBIDFactory {
@Override
final public DBID generateSingleDBID() {
final int id = next.getAndIncrement();
- if (id == Integer.MAX_VALUE) {
+ if(id == Integer.MAX_VALUE) {
throw new AbortException("DBID allocation error - too many objects allocated!");
}
DBID ret = new IntegerDBID(id);
@@ -70,7 +70,7 @@ final public class TrivialDBIDFactory extends AbstractIntegerDBIDFactory {
@Override
final public DBIDRange generateStaticDBIDRange(int size) {
final int start = next.getAndAdd(size);
- if (start > next.get()) {
+ if(start > next.get()) {
throw new AbortException("DBID range allocation error - too many objects allocated!");
}
DBIDRange alloc = new IntegerDBIDRange(start, size);
@@ -78,6 +78,22 @@ final public class TrivialDBIDFactory extends AbstractIntegerDBIDFactory {
}
@Override
+ public DBIDRange generateStaticDBIDRange(int begin, int size) {
+ final int end = begin + size;
+ if(end > Integer.MAX_VALUE) {
+ throw new AbortException("DBID range allocation error - too many objects allocated!");
+ }
+ DBIDRange alloc = new IntegerDBIDRange(begin, size);
+ int v;
+ while((v = next.get()) < end) {
+ if(next.compareAndSet(v, end)) {
+ break;
+ }
+ }
+ return alloc;
+ }
+
+ @Override
public void deallocateDBIDRange(DBIDRange range) {
// ignore.
}
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/TroveHashSetModifiableDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/TroveHashSetModifiableDBIDs.java
index 35276606..61007e10 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/TroveHashSetModifiableDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/TroveHashSetModifiableDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -184,8 +184,9 @@ class TroveHashSetModifiableDBIDs implements HashSetModifiableDBIDs, IntegerDBID
}
@Override
- public void advance() {
+ public IntegerDBIDMIter advance() {
it.advance();
+ return this;
}
@Override
@@ -237,8 +238,9 @@ class TroveHashSetModifiableDBIDs implements HashSetModifiableDBIDs, IntegerDBID
}
@Override
- public void advance() {
+ public Iter advance() {
this._index = nextIndex();
+ return this;
}
@Override
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/UnmodifiableIntegerArrayDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/UnmodifiableIntegerArrayDBIDs.java
index d1c37ab9..1e68cb5a 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/UnmodifiableIntegerArrayDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/UnmodifiableIntegerArrayDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -24,6 +24,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
*/
import de.lmu.ifi.dbs.elki.database.ids.DBID;
+import de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter;
import de.lmu.ifi.dbs.elki.database.ids.DBIDMIter;
import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
import de.lmu.ifi.dbs.elki.database.ids.DBIDVar;
@@ -65,7 +66,7 @@ public class UnmodifiableIntegerArrayDBIDs implements IntegerArrayStaticDBIDs {
@Override
public IntegerDBIDArrayIter iter() {
IntegerDBIDArrayIter it = inner.iter();
- if (it instanceof DBIDMIter) {
+ if(it instanceof DBIDMIter) {
return new UnmodifiableDBIDIter(it);
}
return it;
@@ -128,23 +129,27 @@ public class UnmodifiableIntegerArrayDBIDs implements IntegerArrayStaticDBIDs {
}
@Override
- public void advance() {
+ public DBIDArrayIter advance() {
it.advance();
+ return this;
}
@Override
- public void advance(int count) {
+ public DBIDArrayIter advance(int count) {
it.advance(count);
+ return this;
}
@Override
- public void retract() {
+ public DBIDArrayIter retract() {
it.retract();
+ return this;
}
@Override
- public void seek(int off) {
+ public DBIDArrayIter seek(int off) {
it.seek(off);
+ return this;
}
@Override
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/UnmodifiableIntegerDBIDs.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/UnmodifiableIntegerDBIDs.java
index a3f03bd9..6ac91c5e 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/UnmodifiableIntegerDBIDs.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/UnmodifiableIntegerDBIDs.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,6 +23,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
import de.lmu.ifi.dbs.elki.database.ids.DBIDMIter;
import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
import de.lmu.ifi.dbs.elki.database.ids.StaticDBIDs;
@@ -107,8 +108,9 @@ public class UnmodifiableIntegerDBIDs implements StaticDBIDs, IntegerDBIDs {
}
@Override
- public void advance() {
+ public DBIDIter advance() {
it.advance();
+ return this;
}
@Override
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/package-info.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/package-info.java
index 74a39fb9..661a9cf4 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/package-info.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/package-info.java
@@ -10,7 +10,7 @@
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
-Copyright (C) 2013
+Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/package-info.java b/src/de/lmu/ifi/dbs/elki/database/ids/package-info.java
index eb0a6733..b4c8fd1f 100644
--- a/src/de/lmu/ifi/dbs/elki/database/ids/package-info.java
+++ b/src/de/lmu/ifi/dbs/elki/database/ids/package-info.java
@@ -57,8 +57,6 @@
* </ul>
*
* <h2>Generic utility classes:</h2>
- * <p>{@link de.lmu.ifi.dbs.elki.database.ids.generic.MergedDBIDs MergedDBIDs}
- * allows virtual concatenation of multiple DBIDs objects.</p>
*
* <p>{@link de.lmu.ifi.dbs.elki.database.ids.generic.MaskedDBIDs MaskedDBIDs}
* allows masking an ArrayDBIDs with a BitSet.</p>
@@ -69,21 +67,17 @@
* @apiviz.exclude de.lmu.ifi.dbs.elki.database.ids.EmptyDBIDs.EmptyDBIDIterator
* @apiviz.exclude de.lmu.ifi.dbs.elki.database.*Database
* @apiviz.exclude de.lmu.ifi.dbs.elki.data.Cluster
- * @apiviz.exclude de.lmu.ifi.dbs.elki.utilities.*
* @apiviz.exclude de.lmu.ifi.dbs.elki.datasource.filter.*
* @apiviz.exclude de.lmu.ifi.dbs.elki.database.query.*
- * @apiviz.exclude de.lmu.ifi.dbs.elki.distance.*
- * @apiviz.exclude de.lmu.ifi.dbs.elki.index.*
- * @apiviz.exclude de.lmu.ifi.dbs.elki.result.*
- * @apiviz.exclude de.lmu.ifi.dbs.elki.persistent.*
- * @apiviz.exclude de.lmu.ifi.dbs.elki.algorithm.*
+ * @apiviz.exclude de.lmu.ifi.dbs.elki.(algorithm|evaluation|parallel|distance|index|result|persistent|utilities).*
+ * @apiviz.exclude de.lmu.ifi.dbs.elki.database.relation.*
* @apiviz.exclude java.*
*/
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team