diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreUtil.java')
-rw-r--r-- | src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreUtil.java | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreUtil.java b/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreUtil.java index 6d0c2d0f..5369dda9 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreUtil.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreUtil.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore; 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,10 @@ package de.lmu.ifi.dbs.elki.database.datastore; along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import java.util.Comparator; + +import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; import de.lmu.ifi.dbs.elki.database.ids.DBIDs; -import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance; /** * Storage utility class. Mostly a shorthand for @@ -126,15 +128,60 @@ public final class DataStoreUtil { } /** - * Make a new storage, to associate the given ids with an double valued - * distance. + * Sort objects by a double relation * - * @param ids DBIDs to store data for - * @param hints Hints for the storage manager - * @return new data store + * @author Erich Schubert + * + * @apiviz.exclude */ - public static WritableDoubleDistanceDataStore makeDoubleDistanceStorage(DBIDs ids, int hints) { - // FIXME: this is an ugly work-around. - return (WritableDoubleDistanceDataStore) DataStoreFactory.FACTORY.makeStorage(ids, hints, DoubleDistance.class); + public static class AscendingByDoubleDataStore implements Comparator<DBIDRef> { + /** + * Scores to use for sorting. + */ + private final DoubleDataStore scores; + + /** + * Constructor. + * + * @param scores Scores for sorting + */ + public AscendingByDoubleDataStore(DoubleDataStore scores) { + super(); + this.scores = scores; + } + + @Override + public int compare(DBIDRef id1, DBIDRef id2) { + return Double.compare(scores.doubleValue(id1), scores.doubleValue(id2)); + } + } + + /** + * Sort objects by a double relation + * + * @author Erich Schubert + * + * @apiviz.exclude + */ + public static class DescendingByDoubleDataStore implements Comparator<DBIDRef> { + /** + * Scores to use for sorting. + */ + private final DoubleDataStore scores; + + /** + * Constructor. + * + * @param scores Scores for sorting + */ + public DescendingByDoubleDataStore(DoubleDataStore scores) { + super(); + this.scores = scores; + } + + @Override + public int compare(DBIDRef id1, DBIDRef id2) { + return Double.compare(scores.doubleValue(id2), scores.doubleValue(id1)); + } } } |