summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/database/datastore
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/database/datastore')
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/DataStore.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreEvent.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreFactory.java32
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreIDMap.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreListener.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/DataStoreUtil.java13
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/DoubleDataStore.java44
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/RangeIDMap.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/RecordStore.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/WritableDataStore.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/WritableDoubleDataStore.java59
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/WritableRecordStore.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDoubleStore.java121
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayRecordStore.java6
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayStore.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDoubleStore.java98
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDRecordStore.java191
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDStore.java104
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapRecordStore.java4
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapStore.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/memory/MemoryDataStoreFactory.java34
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/memory/package-info.java2
-rw-r--r--src/de/lmu/ifi/dbs/elki/database/datastore/package-info.java4
23 files changed, 694 insertions, 38 deletions
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 1b0a714c..8d7f73ce 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) 2011
+ Copyright (C) 2012
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 a6849360..5c0a6836 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) 2011
+Copyright (C) 2012
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 d83c9a1c..65a1265d 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) 2011
+ Copyright (C) 2012
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -42,34 +42,35 @@ public interface DataStoreFactory {
* Static storage factory
*/
public static DataStoreFactory FACTORY = new MemoryDataStoreFactory();
-
+
/**
* Storage will be used only temporary.
*/
public final static int HINT_TEMP = 0x01;
-
+
/**
* "Hot" data, that will be used a lot, preferring memory storage.
*/
public final static int HINT_HOT = 0x02;
-
+
/**
* "static" data, that will not change often
*/
public final static int HINT_STATIC = 0x04;
-
+
/**
* Data that might require sorted access (so hashmaps are suboptimal)
*/
public final static int HINT_SORTED = 0x08;
-
+
/**
* Data that is the main database. Includes HOT, STATIC, SORTED
*/
public final static int HINT_DB = 0x1E;
-
+
/**
- * Make a new storage, to associate the given ids with an object of class dataclass.
+ * Make a new storage, to associate the given ids with an object of class
+ * dataclass.
*
* @param <T> stored data type
* @param ids DBIDs to store data for
@@ -78,9 +79,20 @@ public interface DataStoreFactory {
* @return new data store
*/
public <T> WritableDataStore<T> makeStorage(DBIDs ids, int hints, Class<? super T> dataclass);
-
+
+ /**
+ * Make a new storage, to associate the given ids with an object of class
+ * dataclass.
+ *
+ * @param ids DBIDs to store data for
+ * @param hints Hints for the storage manager
+ * @return new data store
+ */
+ public WritableDoubleDataStore makeDoubleStorage(DBIDs ids, int hints);
+
/**
- * Make a new record storage, to associate the given ids with an object of class dataclass.
+ * Make a new record storage, to associate the given ids with an object of
+ * class dataclass.
*
* @param ids DBIDs to store data for
* @param hints Hints for the storage manager
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 21b876ce..ead75709 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) 2011
+ Copyright (C) 2012
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 02d5db77..609fe67d 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) 2011
+ Copyright (C) 2012
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 6e7af03d..f299c1e8 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) 2011
+ Copyright (C) 2012
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -48,6 +48,17 @@ public final class DataStoreUtil {
}
/**
+ * Make a new storage, to associate the given ids with an object of class dataclass.
+ *
+ * @param ids DBIDs to store data for
+ * @param hints Hints for the storage manager
+ * @return new data store
+ */
+ public static WritableDoubleDataStore makeDoubleStorage(DBIDs ids, int hints) {
+ return DataStoreFactory.FACTORY.makeDoubleStorage(ids, hints);
+ }
+
+ /**
* Make a new record storage, to associate the given ids with an object of class dataclass.
*
* @param ids DBIDs to store data for
diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/DoubleDataStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/DoubleDataStore.java
new file mode 100644
index 00000000..ee315a0c
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/database/datastore/DoubleDataStore.java
@@ -0,0 +1,44 @@
+package de.lmu.ifi.dbs.elki.database.datastore;
+
+import de.lmu.ifi.dbs.elki.database.ids.DBID;
+
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2012
+ 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/>.
+ */
+
+/**
+ * Double-valued data store (avoids boxing/unboxing).
+ *
+ * @author Erich Schubert
+ */
+public interface DoubleDataStore extends DataStore<Double> {
+ @Deprecated
+ public Double get(DBID id);
+
+ /**
+ * Retrieves an object from the storage.
+ *
+ * @param id Database ID.
+ * @return Double value
+ */
+ public double doubleValue(DBID id);
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/database/datastore/RangeIDMap.java b/src/de/lmu/ifi/dbs/elki/database/datastore/RangeIDMap.java
index 85a0f4c4..7fc0ed7f 100644
--- a/src/de/lmu/ifi/dbs/elki/database/datastore/RangeIDMap.java
+++ b/src/de/lmu/ifi/dbs/elki/database/datastore/RangeIDMap.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) 2011
+ Copyright (C) 2012
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 31bbbc3b..508dae8e 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) 2011
+ Copyright (C) 2012
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 a06c4b3f..7f1fbf52 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) 2011
+ Copyright (C) 2012
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
new file mode 100644
index 00000000..313e4adc
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/database/datastore/WritableDoubleDataStore.java
@@ -0,0 +1,59 @@
+package de.lmu.ifi.dbs.elki.database.datastore;
+
+import de.lmu.ifi.dbs.elki.database.ids.DBID;
+
+/*
+ This file is part of ELKI:
+ Environment for Developing KDD-Applications Supported by Index-Structures
+
+ Copyright (C) 2012
+ 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/>.
+ */
+
+/**
+ * Data store specialized for doubles. Avoids boxing/unboxing.
+ *
+ * @author Erich Schubert
+ */
+public interface WritableDoubleDataStore extends DoubleDataStore, WritableDataStore<Double> {
+ @Override
+ @Deprecated
+ public Double put(DBID 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 putDouble(DBID 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(DBID id, double value);
+} \ No newline at end of file
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 749acb0a..775d201b 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) 2011
+ Copyright (C) 2012
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/ArrayDoubleStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDoubleStore.java
new file mode 100644
index 00000000..433547a5
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayDoubleStore.java
@@ -0,0 +1,121 @@
+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) 2012
+ 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.datastore.DataStoreIDMap;
+import de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore;
+import de.lmu.ifi.dbs.elki.database.ids.DBID;
+
+/**
+ * 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 ArrayDoubleStore implements WritableDoubleDataStore {
+ /**
+ * Data array
+ */
+ private double[] data;
+
+ /**
+ * DBID to index map
+ */
+ private DataStoreIDMap idmap;
+
+ /**
+ * Constructor.
+ *
+ * @param size Size
+ * @param idmap ID map
+ */
+ public ArrayDoubleStore(int size, DataStoreIDMap idmap) {
+ super();
+ this.data = new double[size];
+ this.idmap = idmap;
+ }
+
+ @Override
+ @Deprecated
+ public Double get(DBID id) {
+ try {
+ return data[idmap.map(id)];
+ }
+ catch(ArrayIndexOutOfBoundsException e) {
+ return null;
+ }
+ }
+
+ @Override
+ @Deprecated
+ public Double put(DBID id, Double value) {
+ final int off = idmap.map(id);
+ double ret = data[off];
+ data[off] = value;
+ return ret;
+ }
+
+ @Override
+ public double doubleValue(DBID id) {
+ return data[idmap.map(id)];
+ }
+
+ @Override
+ public double putDouble(DBID id, double value) {
+ final int off = idmap.map(id);
+ final double ret = data[off];
+ data[off] = value;
+ return ret;
+ }
+
+ @Override
+ public double put(DBID id, double value) {
+ final int off = idmap.map(id);
+ final double ret = data[off];
+ data[off] = value;
+ return ret;
+ }
+
+ @Override
+ public void destroy() {
+ data = null;
+ idmap = null;
+ }
+
+ @Override
+ public void delete(DBID id) {
+ throw new UnsupportedOperationException("Can't delete from a static array storage.");
+ }
+
+ @Override
+ public String getLongName() {
+ return "raw";
+ }
+
+ @Override
+ public String getShortName() {
+ return "raw";
+ }
+} \ No newline at end of file
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 507fe15b..7be68c97 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) 2011
+ Copyright (C) 2012
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -33,8 +33,8 @@ import de.lmu.ifi.dbs.elki.database.ids.DBID;
*
* @author Erich Schubert
*
- * @apiviz.composedOf de.lmu.ifi.dbs.elki.database.datastore.DataStoreIDMap
- * @apiviz.has de.lmu.ifi.dbs.elki.database.datastore.memory.ArrayRecordStore.StorageAccessor oneway - - projectsTo
+ * @apiviz.composedOf DataStoreIDMap
+ * @apiviz.has ArrayRecordStore.StorageAccessor oneway - - projectsTo
*/
public class ArrayRecordStore implements WritableRecordStore {
/**
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 96cadddf..a41a444d 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) 2011
+ Copyright (C) 2012
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/MapIntegerDBIDDoubleStore.java b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDoubleStore.java
new file mode 100644
index 00000000..ae06dc00
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDDoubleStore.java
@@ -0,0 +1,98 @@
+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) 2012
+ 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.WritableDoubleDataStore;
+import de.lmu.ifi.dbs.elki.database.ids.DBID;
+
+/**
+ * Writable data store for double values.
+ *
+ * @author Erich Schubert
+ */
+public class MapIntegerDBIDDoubleStore implements WritableDoubleDataStore {
+ /**
+ * Data storage
+ */
+ private TIntDoubleMap map;
+
+ /**
+ * Constructor.
+ *
+ * @param size Expected size
+ */
+ public MapIntegerDBIDDoubleStore(int size) {
+ super();
+ map = new TIntDoubleHashMap(size, 0.5f, Integer.MIN_VALUE, Double.NaN);
+ }
+
+ @Override
+ @Deprecated
+ public Double get(DBID id) {
+ return map.get(id.getIntegerID());
+ }
+
+ @Override
+ public double doubleValue(DBID id) {
+ return map.get(id.getIntegerID());
+ }
+
+ @Override
+ public String getLongName() {
+ return "raw";
+ }
+
+ @Override
+ public String getShortName() {
+ return "raw";
+ }
+
+ @Override
+ @Deprecated
+ public Double put(DBID id, Double value) {
+ return map.put(id.getIntegerID(), value);
+ }
+
+ @Override
+ public void destroy() {
+ map.clear();
+ map = null;
+ }
+
+ @Override
+ public void delete(DBID id) {
+ map.remove(id.getIntegerID());
+ }
+
+ @Override
+ public double putDouble(DBID id, double value) {
+ return map.put(id.getIntegerID(), value);
+ }
+
+ @Override
+ public double put(DBID id, double value) {
+ return map.put(id.getIntegerID(), value);
+ }
+}
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
new file mode 100644
index 00000000..8272fb2e
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDRecordStore.java
@@ -0,0 +1,191 @@
+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) 2012
+ 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.TIntObjectMap;
+import gnu.trove.map.hash.TIntObjectHashMap;
+import de.lmu.ifi.dbs.elki.database.datastore.WritableDataStore;
+import de.lmu.ifi.dbs.elki.database.datastore.WritableRecordStore;
+import de.lmu.ifi.dbs.elki.database.ids.DBID;
+
+/**
+ * A class to answer representation queries using a map and an index within the
+ * record.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.has MapIntegerDBIDRecordStore.StorageAccessor oneway - - projectsTo
+ */
+public class MapIntegerDBIDRecordStore implements WritableRecordStore {
+ /**
+ * Record length
+ */
+ private final int rlen;
+
+ /**
+ * Storage Map
+ */
+ private final TIntObjectMap<Object[]> data;
+
+ /**
+ * Constructor with existing data.
+ *
+ * @param rlen Number of columns (record length)
+ * @param data Existing data map
+ */
+ public MapIntegerDBIDRecordStore(int rlen, TIntObjectMap<Object[]> data) {
+ super();
+ this.rlen = rlen;
+ this.data = data;
+ }
+
+ /**
+ * Constructor without existing data.
+ *
+ * @param rlen Number of columns (record length)
+ */
+ public MapIntegerDBIDRecordStore(int rlen) {
+ this(rlen, new TIntObjectHashMap<Object[]>());
+ }
+
+ /**
+ * Constructor without existing data.
+ *
+ * @param size Expected size
+ * @param rlen Number of columns (record length)
+ */
+ public MapIntegerDBIDRecordStore(int size, int rlen) {
+ this(rlen, new TIntObjectHashMap<Object[]>(size));
+ }
+
+ @Override
+ public <T> WritableDataStore<T> getStorage(int col, Class<? super T> datatype) {
+ // TODO: add type checking?
+ return new StorageAccessor<T>(col);
+ }
+
+ /**
+ * Actual getter
+ *
+ * @param id Database ID
+ * @param index column index
+ * @return current value
+ */
+ @SuppressWarnings("unchecked")
+ protected <T> T get(DBID id, int index) {
+ Object[] d = data.get(id.getIntegerID());
+ if(d == null) {
+ return null;
+ }
+ try {
+ return (T) d[index];
+ }
+ catch(ClassCastException e) {
+ return null;
+ }
+ catch(ArrayIndexOutOfBoundsException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Actual setter
+ *
+ * @param id Database ID
+ * @param index column index
+ * @param value new value
+ * @return previous value
+ */
+ @SuppressWarnings("unchecked")
+ protected <T> T set(DBID id, int index, T value) {
+ Object[] d = data.get(id.getIntegerID());
+ if(d == null) {
+ d = new Object[rlen];
+ data.put(id.getIntegerID(), d);
+ }
+ T ret = (T) d[index];
+ d[index] = value;
+ return ret;
+ }
+
+ /**
+ * Access a single record in the given data.
+ *
+ * @author Erich Schubert
+ *
+ * @param <T> Object data type to access
+ */
+ protected class StorageAccessor<T> implements WritableDataStore<T> {
+ /**
+ * Representation index.
+ */
+ private final int index;
+
+ /**
+ * Constructor.
+ *
+ * @param index In-record index
+ */
+ protected StorageAccessor(int index) {
+ super();
+ this.index = index;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T get(DBID id) {
+ return (T) MapIntegerDBIDRecordStore.this.get(id, index);
+ }
+
+ @Override
+ public T put(DBID id, T value) {
+ return MapIntegerDBIDRecordStore.this.set(id, index, value);
+ }
+
+ @Override
+ public void destroy() {
+ throw new UnsupportedOperationException("Record storage accessors cannot be destroyed.");
+ }
+
+ @Override
+ public void delete(DBID id) {
+ throw new UnsupportedOperationException("Record storage values cannot be deleted.");
+ }
+
+ @Override
+ public String getLongName() {
+ return "raw";
+ }
+
+ @Override
+ public String getShortName() {
+ return "raw";
+ }
+ }
+
+ @Override
+ public boolean remove(DBID id) {
+ return data.remove(id.getIntegerID()) != null;
+ }
+} \ No newline at end of file
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
new file mode 100644
index 00000000..4deb929d
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDStore.java
@@ -0,0 +1,104 @@
+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) 2012
+ 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.TIntObjectMap;
+import gnu.trove.map.hash.TIntObjectHashMap;
+import de.lmu.ifi.dbs.elki.database.datastore.WritableDataStore;
+import de.lmu.ifi.dbs.elki.database.ids.DBID;
+
+/**
+ * A class to answer representation queries using a map. Basically, it is just a
+ * wrapper around a regular map.
+ *
+ * @author Erich Schubert
+ *
+ * @param <T> Representation object type
+ */
+public class MapIntegerDBIDStore<T> implements WritableDataStore<T> {
+ /**
+ * Storage Map
+ */
+ private TIntObjectMap<T> data;
+
+ /**
+ * Constructor.
+ *
+ * @param data Existing map
+ */
+ public MapIntegerDBIDStore(TIntObjectMap<T> data) {
+ super();
+ this.data = data;
+ }
+
+ /**
+ * Constructor.
+ */
+ public MapIntegerDBIDStore() {
+ super();
+ this.data = new TIntObjectHashMap<T>();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param size Expected size
+ */
+ public MapIntegerDBIDStore(int size) {
+ this.data = new TIntObjectHashMap<T>(size);
+ }
+
+ @Override
+ public T get(DBID id) {
+ return data.get(id.getIntegerID());
+ }
+
+ @Override
+ public T put(DBID id, T value) {
+ if(value == null) {
+ return data.remove(id.getIntegerID());
+ }
+ return data.put(id.getIntegerID(), value);
+ }
+
+ @Override
+ public void destroy() {
+ data = null;
+ }
+
+ @Override
+ public void delete(DBID id) {
+ data.remove(id.getIntegerID());
+ }
+
+ @Override
+ public String getLongName() {
+ return "raw";
+ }
+
+ @Override
+ public String getShortName() {
+ return "raw";
+ }
+} \ No newline at end of file
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 31efc613..5a98966f 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) 2011
+ Copyright (C) 2012
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -36,7 +36,7 @@ import de.lmu.ifi.dbs.elki.database.ids.DBID;
*
* @author Erich Schubert
*
- * @apiviz.has de.lmu.ifi.dbs.elki.database.datastore.memory.MapRecordStore.StorageAccessor oneway - - projectsTo
+ * @apiviz.has MapRecordStore.StorageAccessor oneway - - projectsTo
*/
public class MapRecordStore implements WritableRecordStore {
/**
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 e8a806ec..27cd9f63 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) 2011
+ Copyright (C) 2012
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 2c64ee55..3e3ce017 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) 2011
+ Copyright (C) 2012
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -26,14 +26,17 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory;
import de.lmu.ifi.dbs.elki.database.datastore.DataStoreFactory;
import de.lmu.ifi.dbs.elki.database.datastore.RangeIDMap;
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.WritableRecordStore;
import de.lmu.ifi.dbs.elki.database.ids.DBIDRange;
import de.lmu.ifi.dbs.elki.database.ids.DBIDs;
/**
- * Simple factory class that will store all data in memory using object arrays or hashmaps.
+ * Simple factory class that will store all data in memory using object arrays
+ * or hashmaps.
*
- * Hints are currently not used by this implementation, since everything is in-memory.
+ * Hints are currently not used by this implementation, since everything is
+ * in-memory.
*
* @author Erich Schubert
*
@@ -46,23 +49,36 @@ import de.lmu.ifi.dbs.elki.database.ids.DBIDs;
public class MemoryDataStoreFactory implements DataStoreFactory {
@Override
public <T> WritableDataStore<T> makeStorage(DBIDs ids, int hints, Class<? super T> dataclass) {
- if (ids instanceof DBIDRange) {
+ if(ids instanceof DBIDRange) {
DBIDRange range = (DBIDRange) ids;
Object[] data = new Object[range.size()];
return new ArrayStore<T>(data, new RangeIDMap(range));
- } else {
- return new MapStore<T>();
+ }
+ else {
+ return new MapIntegerDBIDStore<T>(ids.size());
+ }
+ }
+
+ @Override
+ public WritableDoubleDataStore makeDoubleStorage(DBIDs ids, int hints) {
+ if(ids instanceof DBIDRange) {
+ DBIDRange range = (DBIDRange) ids;
+ return new ArrayDoubleStore(range.size(), new RangeIDMap(range));
+ }
+ else {
+ return new MapIntegerDBIDDoubleStore(ids.size());
}
}
@Override
public WritableRecordStore makeRecordStorage(DBIDs ids, int hints, Class<?>... dataclasses) {
- if (ids instanceof DBIDRange) {
+ if(ids instanceof DBIDRange) {
DBIDRange range = (DBIDRange) ids;
Object[][] data = new Object[range.size()][dataclasses.length];
return new ArrayRecordStore(data, new RangeIDMap(range));
- } else {
- return new MapRecordStore(dataclasses.length);
+ }
+ else {
+ 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 c0f41618..6200bb46 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) 2011
+Copyright (C) 2012
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 02ef6f6c..dccd8d4e 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
@@ -14,7 +14,7 @@
* <h2>How to use:</h2>
* <pre>{@code
* // Storage for the outlier score of each ID.
- * final WritableDataStore<Double> scores = DataStoreFactory.FACTORY.makeStorage(ids, DataStoreFactory.HINT_STATIC, Double.class);
+ * final WritableDoubleDataStore scores = DataStoreFactory.FACTORY.makeDoubleStorage(ids, DataStoreFactory.HINT_STATIC);
* }</pre>
*
* @apiviz.exclude datastore.memory
@@ -23,7 +23,7 @@
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
-Copyright (C) 2011
+Copyright (C) 2012
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team