diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/database/datastore')
34 files changed, 148 insertions, 440 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/DBIDDataStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/DBIDDataStore.java index 8c0eb2cb..8100fb66 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/DBIDDataStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/DBIDDataStore.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 diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/DataStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/DataStore.java index 384680c6..368488f2 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/DataStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/DataStore.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 diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreEvent.java b/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreEvent.java index 7942fb9b..5b374a4e 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreEvent.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreEvent.java @@ -3,7 +3,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 diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreFactory.java b/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreFactory.java index 7b3cd0e7..2695f51f 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreFactory.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreFactory.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 @@ -34,8 +34,11 @@ import de.lmu.ifi.dbs.elki.database.ids.DBIDs; * @author Erich Schubert * * @apiviz.stereotype factory,interface - * @apiviz.uses WritableDataStore oneway - - «create» - * @apiviz.uses WritableRecordStore oneway - - «create» + * @apiviz.has WritableDataStore oneway - - «create» + * @apiviz.has WritableIntegerDataStore oneway - - «create» + * @apiviz.has WritableDoubleDataStore oneway - - «create» + * @apiviz.has WritableDBIDDataStore oneway - - «create» + * @apiviz.has WritableRecordStore oneway - - «create» */ public interface DataStoreFactory { /** diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreIDMap.java b/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreIDMap.java index adfd1354..215c660f 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreIDMap.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreIDMap.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 diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreListener.java b/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreListener.java index a3f1319d..e437af78 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreListener.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreListener.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 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)); + } } } diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/DoubleDataStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/DoubleDataStore.java index b121d195..0995d40a 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/DoubleDataStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/DoubleDataStore.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 diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/DoubleDistanceDataStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/DoubleDistanceDataStore.java deleted file mode 100644 index 88b9d4dc..00000000 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/DoubleDistanceDataStore.java +++ /dev/null @@ -1,51 +0,0 @@ -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 - 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; - -/** - * Double-valued data store (avoids boxing/unboxing). - * - * @author Erich Schubert - */ -public interface DoubleDistanceDataStore extends DataStore<DoubleDistance> { - /** - * Getter, but using objects. - * - * @deprecated Use {@link #doubleValue} instead, to avoid boxing/unboxing cost. - */ - @Override - @Deprecated - public DoubleDistance get(DBIDRef id); - - /** - * Retrieves an object from the storage. - * - * @param id Database ID. - * @return Double value - */ - public double doubleValue(DBIDRef id); -}
\ No newline at end of file diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/IntegerDataStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/IntegerDataStore.java index 969e2228..45b5f43c 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/IntegerDataStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/IntegerDataStore.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 diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/RecordStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/RecordStore.java index 07bf2dcf..e7f6adc1 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/RecordStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/RecordStore.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 diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDBIDDataStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDBIDDataStore.java index bae55a57..d7bf02bc 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDBIDDataStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDBIDDataStore.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 diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDataStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDataStore.java index c62fc721..c746eda3 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDataStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDataStore.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 diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDoubleDataStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDoubleDataStore.java index a40f0ef4..7755d0de 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDoubleDataStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDoubleDataStore.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 @@ -61,4 +61,18 @@ public interface WritableDoubleDataStore extends DoubleDataStore, WritableDataSt * @return previous value */ public double put(DBIDRef id, double value); + + + /** + * Increment the specified value with the specified id in this storage. + * + * @param id Database ID. + * @param value Value to add to the previous value. + */ + public void increment(DBIDRef id, double value); + + /** + * Reinitialize (reset to default value). + */ + public void clear(); }
\ No newline at end of file diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDoubleDistanceDataStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDoubleDistanceDataStore.java deleted file mode 100644 index f929d5d7..00000000 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDoubleDistanceDataStore.java +++ /dev/null @@ -1,65 +0,0 @@ -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 - 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; - -/** - * Data store specialized for doubles. Avoids boxing/unboxing. - * - * @author Erich Schubert - */ -public interface WritableDoubleDistanceDataStore extends DoubleDistanceDataStore, WritableDataStore<DoubleDistance> { - /** - * Setter, but using objects. - * - * @deprecated Use {@link #putDouble} instead, to avoid boxing/unboxing cost. - */ - @Override - @Deprecated - public DoubleDistance put(DBIDRef id, DoubleDistance value); - - /** - * Associates the specified value with the specified id in this storage. If - * the storage previously contained a value for the id, the previous value is - * replaced by the specified value. - * - * @param id Database ID. - * @param value Value to store. - * @return previous value - */ - public double putDouble(DBIDRef id, double value); - - /** - * Associates the specified value with the specified id in this storage. If - * the storage previously contained a value for the id, the previous value is - * replaced by the specified value. - * - * @param id Database ID. - * @param value Value to store. - * @return previous value - */ - public double put(DBIDRef id, double value); -}
\ No newline at end of file diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/WritableIntegerDataStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/WritableIntegerDataStore.java index fb323b02..2c0e61e9 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/WritableIntegerDataStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/WritableIntegerDataStore.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 diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/WritableRecordStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/WritableRecordStore.java index c4c182e9..8d0c58fd 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/WritableRecordStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/WritableRecordStore.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 diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDBIDStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDBIDStore.java index 78cb51d2..2134c75a 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDBIDStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDBIDStore.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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/datastore/memory/ArrayDoubleDistanceStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDoubleDistanceStore.java deleted file mode 100644 index abb81d95..00000000 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDoubleDistanceStore.java +++ /dev/null @@ -1,133 +0,0 @@ -package de.lmu.ifi.dbs.elki.database.datastore.memory; - -/* - 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.datastore.DataStoreIDMap; -import de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDistanceDataStore; -import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; -import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance; - -/** - * A class to answer representation queries using the stored Array. - * - * @author Erich Schubert - * - * @apiviz.composedOf de.lmu.ifi.dbs.elki.database.datastore.DataStoreIDMap - */ -public class ArrayDoubleDistanceStore implements WritableDoubleDistanceDataStore { - /** - * Data array - */ - private double[] data; - - /** - * DBID to index map - */ - private DataStoreIDMap idmap; - - /** - * Constructor. - * - * @param size Size - * @param idmap ID map - */ - public ArrayDoubleDistanceStore(int size, DataStoreIDMap idmap) { - this(size, idmap, Double.NaN); - } - - /** - * Constructor. - * - * @param size Size - * @param idmap ID map - * @param def Default value - */ - public ArrayDoubleDistanceStore(int size, DataStoreIDMap idmap, double def) { - super(); - this.data = new double[size]; - if (def != 0) { - Arrays.fill(this.data, def); - } - this.idmap = idmap; - } - - @Override - @Deprecated - public DoubleDistance get(DBIDRef id) { - return new DoubleDistance(data[idmap.mapDBIDToOffset(id)]); - } - - @Override - @Deprecated - public DoubleDistance put(DBIDRef id, DoubleDistance value) { - final int off = idmap.mapDBIDToOffset(id); - double ret = data[off]; - data[off] = value.doubleValue(); - return new DoubleDistance(ret); - } - - @Override - public double doubleValue(DBIDRef id) { - return data[idmap.mapDBIDToOffset(id)]; - } - - @Override - public double putDouble(DBIDRef id, double value) { - final int off = idmap.mapDBIDToOffset(id); - final double ret = data[off]; - data[off] = value; - return ret; - } - - @Override - public double put(DBIDRef id, double value) { - final int off = idmap.mapDBIDToOffset(id); - final double ret = data[off]; - data[off] = value; - return ret; - } - - @Override - public void destroy() { - data = null; - idmap = null; - } - - @Override - public void delete(DBIDRef id) { - throw new UnsupportedOperationException("Can't delete from a static array storage."); - } - - @Override - public String getLongName() { - return "raw"; - } - - @Override - public String getShortName() { - return "raw"; - } -} diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDoubleStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDoubleStore.java index c41991eb..8b2ec127 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDoubleStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDoubleStore.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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 @@ -41,6 +41,11 @@ public class ArrayDoubleStore implements WritableDoubleDataStore { * Data array */ private double[] data; + + /** + * Default value. + */ + private double def; /** * DBID to index map @@ -67,9 +72,10 @@ public class ArrayDoubleStore implements WritableDoubleDataStore { public ArrayDoubleStore(int size, DataStoreIDMap idmap, double def) { super(); this.data = new double[size]; - if (def != 0) { + if(def != 0) { Arrays.fill(this.data, def); } + this.def = def; this.idmap = idmap; } @@ -110,6 +116,16 @@ public class ArrayDoubleStore implements WritableDoubleDataStore { } @Override + public void increment(DBIDRef id, double value) { + data[idmap.mapDBIDToOffset(id)] += value; + } + + @Override + public void clear() { + Arrays.fill(data, def); + } + + @Override public void destroy() { data = null; idmap = null; diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayIntegerStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayIntegerStore.java index b8a76646..29541065 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayIntegerStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayIntegerStore.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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/datastore/memory/ArrayRecordStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayRecordStore.java index e9c78cb7..2fac747f 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayRecordStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayRecordStore.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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/datastore/memory/ArrayStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayStore.java index 695ddc48..b0e5add8 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayStore.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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/datastore/memory/MapIntegerDBIDDBIDStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDBIDStore.java index 9b8a4be8..ed60cf0a 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDBIDStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDBIDStore.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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 @@ -50,7 +50,7 @@ public class MapIntegerDBIDDBIDStore implements WritableDBIDDataStore { */ public MapIntegerDBIDDBIDStore(int size) { super(); - map = new TIntIntHashMap(size, 0.5f, Integer.MIN_VALUE, DBIDUtil.invalid().internalGetIndex()); + map = new TIntIntHashMap(size, 0.5f, Integer.MIN_VALUE, DBIDUtil.asInteger(DBIDUtil.invalid())); } @Override @@ -72,7 +72,7 @@ public class MapIntegerDBIDDBIDStore implements WritableDBIDDataStore { @Override @Deprecated public DBID put(DBIDRef id, DBID value) { - return DBIDUtil.importInteger(map.put(id.internalGetIndex(), value.internalGetIndex())); + return DBIDUtil.importInteger(map.put(DBIDUtil.asInteger(id), DBIDUtil.asInteger(value))); } @Override @@ -88,17 +88,17 @@ public class MapIntegerDBIDDBIDStore implements WritableDBIDDataStore { @Override public void put(DBIDRef id, DBIDRef value) { - map.put(id.internalGetIndex(), value.internalGetIndex()); + map.put(DBIDUtil.asInteger(id), DBIDUtil.asInteger(value)); } @Override public void putDBID(DBIDRef id, DBIDRef value) { - map.put(id.internalGetIndex(), value.internalGetIndex()); + map.put(DBIDUtil.asInteger(id), DBIDUtil.asInteger(value)); } @Override public void assignVar(DBIDRef id, DBIDVar var) { - final int val = map.get(id.internalGetIndex()); + final int val = map.get(DBIDUtil.asInteger(id)); DBIDFactory.FACTORY.assignVar(var, val); } } diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDoubleDistanceStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDoubleDistanceStore.java deleted file mode 100644 index be12b54c..00000000 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDoubleDistanceStore.java +++ /dev/null @@ -1,111 +0,0 @@ -package de.lmu.ifi.dbs.elki.database.datastore.memory; - -/* - 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 gnu.trove.map.TIntDoubleMap; -import gnu.trove.map.hash.TIntDoubleHashMap; -import de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDistanceDataStore; -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.distancevalue.DoubleDistance; - -/** - * Writable data store for double values. - * - * @author Erich Schubert - */ -public class MapIntegerDBIDDoubleDistanceStore implements WritableDoubleDistanceDataStore { - /** - * Data storage. - */ - private TIntDoubleMap map; - - /** - * Constructor. - * - * @param size Expected size - */ - public MapIntegerDBIDDoubleDistanceStore(int size) { - this(size, Double.NaN); - } - - /** - * Constructor. - * - * @param size Expected size - * @param def Default value - */ - public MapIntegerDBIDDoubleDistanceStore(int size, double def) { - super(); - map = new TIntDoubleHashMap(size, 0.5f, Integer.MIN_VALUE, def); - } - - @Override - @Deprecated - public DoubleDistance get(DBIDRef id) { - return new DoubleDistance(map.get(DBIDUtil.asInteger(id))); - } - - @Override - public double doubleValue(DBIDRef id) { - return map.get(DBIDUtil.asInteger(id)); - } - - @Override - public String getLongName() { - return "raw"; - } - - @Override - public String getShortName() { - return "raw"; - } - - @Override - @Deprecated - public DoubleDistance put(DBIDRef id, DoubleDistance value) { - return new DoubleDistance(map.put(DBIDUtil.asInteger(id), value.doubleValue())); - } - - @Override - public void destroy() { - map.clear(); - map = null; - } - - @Override - public void delete(DBIDRef id) { - map.remove(DBIDUtil.asInteger(id)); - } - - @Override - public double putDouble(DBIDRef id, double value) { - return map.put(DBIDUtil.asInteger(id), value); - } - - @Override - public double put(DBIDRef id, double value) { - return map.put(DBIDUtil.asInteger(id), value); - } -} diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDoubleStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDoubleStore.java index 8d73b672..8779eb46 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDoubleStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDoubleStore.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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 @@ -88,12 +88,6 @@ public class MapIntegerDBIDDoubleStore implements WritableDoubleDataStore { } @Override - public void destroy() { - map.clear(); - map = null; - } - - @Override public void delete(DBIDRef id) { map.remove(DBIDUtil.asInteger(id)); } @@ -107,4 +101,20 @@ public class MapIntegerDBIDDoubleStore implements WritableDoubleDataStore { public double put(DBIDRef id, double value) { return map.put(DBIDUtil.asInteger(id), value); } + + @Override + public void increment(DBIDRef id, double value) { + map.adjustOrPutValue(DBIDUtil.asInteger(id), value, map.getNoEntryValue() + value); + } + + @Override + public void clear() { + map.clear(); + } + + @Override + public void destroy() { + map.clear(); + map = null; + } } diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDIntegerStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDIntegerStore.java index 935f23f4..2f2a42a2 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDIntegerStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDIntegerStore.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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/datastore/memory/MapIntegerDBIDRecordStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDRecordStore.java index 9efe2221..7963b78c 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDRecordStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDRecordStore.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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/datastore/memory/MapIntegerDBIDStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDStore.java index ede82f15..55402703 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDStore.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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/datastore/memory/MapRecordStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapRecordStore.java index 045d5bf4..6b5b1a50 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapRecordStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapRecordStore.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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/datastore/memory/MapStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapStore.java index c40e0a72..3432e124 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapStore.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapStore.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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/datastore/memory/MemoryDataStoreFactory.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MemoryDataStoreFactory.java index 2a6cd1cb..2ad2dd05 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MemoryDataStoreFactory.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MemoryDataStoreFactory.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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 @@ -27,12 +27,10 @@ import de.lmu.ifi.dbs.elki.database.datastore.DataStoreFactory; import de.lmu.ifi.dbs.elki.database.datastore.WritableDBIDDataStore; import de.lmu.ifi.dbs.elki.database.datastore.WritableDataStore; import de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore; -import de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDistanceDataStore; import de.lmu.ifi.dbs.elki.database.datastore.WritableIntegerDataStore; import de.lmu.ifi.dbs.elki.database.datastore.WritableRecordStore; import de.lmu.ifi.dbs.elki.database.ids.DBIDRange; import de.lmu.ifi.dbs.elki.database.ids.DBIDs; -import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance; /** * Simple factory class that will store all data in memory using object arrays @@ -44,18 +42,15 @@ import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance; * @author Erich Schubert * * @apiviz.stereotype factory - * @apiviz.uses ArrayStore oneway - - «create» - * @apiviz.uses ArrayRecordStore oneway - - «create» - * @apiviz.uses MapStore oneway - - «create» - * @apiviz.uses MapRecordStore oneway - - «create» + * @apiviz.has ArrayStore oneway - - «create» + * @apiviz.has ArrayRecordStore oneway - - «create» + * @apiviz.has MapStore oneway - - «create» + * @apiviz.has MapRecordStore oneway - - «create» */ public class MemoryDataStoreFactory implements DataStoreFactory { @SuppressWarnings("unchecked") @Override public <T> WritableDataStore<T> makeStorage(DBIDs ids, int hints, Class<? super T> dataclass) { - if (DoubleDistance.class.equals(dataclass)) { - return (WritableDataStore<T>) makeDoubleDistanceStorage(ids, hints); - } if (Double.class.equals(dataclass)) { return (WritableDataStore<T>) makeDoubleStorage(ids, hints); } @@ -83,23 +78,6 @@ public class MemoryDataStoreFactory implements DataStoreFactory { } } - /** - * Make a data storage for double distances. - * - * @param ids IDs to store for - * @param hints Storage hints - * @return double distance storage - */ - public WritableDoubleDistanceDataStore makeDoubleDistanceStorage(DBIDs ids, int hints) { - if(ids instanceof DBIDRange) { - DBIDRange range = (DBIDRange) ids; - return new ArrayDoubleDistanceStore(range.size(), range); - } - else { - return new MapIntegerDBIDDoubleDistanceStore(ids.size()); - } - } - @Override public WritableDoubleDataStore makeDoubleStorage(DBIDs ids, int hints) { if(ids instanceof DBIDRange) { @@ -155,4 +133,4 @@ public class MemoryDataStoreFactory implements DataStoreFactory { return new MapIntegerDBIDRecordStore(ids.size(), dataclasses.length); } } -}
\ No newline at end of file +} diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/package-info.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/package-info.java index 5ea46015..dada2a9b 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/memory/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/package-info.java @@ -5,7 +5,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/datastore/package-info.java b/src/de/lmu/ifi/dbs/elki/database/datastore/package-info.java index f213019d..aa15d1c2 100644 --- a/src/de/lmu/ifi/dbs/elki/database/datastore/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/package-info.java @@ -24,7 +24,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 |