diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/database/datastore/memory')
11 files changed, 373 insertions, 55 deletions
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 433547a5..de22a6b3 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 @@ -23,9 +23,11 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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.WritableDoubleDataStore; -import de.lmu.ifi.dbs.elki.database.ids.DBID; +import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; /** * A class to answer representation queries using the stored Array. @@ -52,14 +54,28 @@ public class ArrayDoubleStore implements WritableDoubleDataStore { * @param idmap ID map */ public ArrayDoubleStore(int size, DataStoreIDMap idmap) { + this(size, idmap, Double.NaN); + } + + /** + * Constructor. + * + * @param size Size + * @param idmap ID map + * @param def Default value + */ + public ArrayDoubleStore(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 Double get(DBID id) { + public Double get(DBIDRef id) { try { return data[idmap.map(id)]; } @@ -70,20 +86,20 @@ public class ArrayDoubleStore implements WritableDoubleDataStore { @Override @Deprecated - public Double put(DBID id, Double value) { + public Double put(DBIDRef id, Double value) { final int off = idmap.map(id); double ret = data[off]; data[off] = value; return ret; } - + @Override - public double doubleValue(DBID id) { + public double doubleValue(DBIDRef id) { return data[idmap.map(id)]; } @Override - public double putDouble(DBID id, double value) { + public double putDouble(DBIDRef id, double value) { final int off = idmap.map(id); final double ret = data[off]; data[off] = value; @@ -91,7 +107,7 @@ public class ArrayDoubleStore implements WritableDoubleDataStore { } @Override - public double put(DBID id, double value) { + public double put(DBIDRef id, double value) { final int off = idmap.map(id); final double ret = data[off]; data[off] = value; @@ -105,7 +121,7 @@ public class ArrayDoubleStore implements WritableDoubleDataStore { } @Override - public void delete(DBID id) { + public void delete(DBIDRef id) { throw new UnsupportedOperationException("Can't delete from a static array storage."); } 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 new file mode 100644 index 00000000..8caa7ec3 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/ArrayIntegerStore.java @@ -0,0 +1,137 @@ +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 java.util.Arrays; + +import de.lmu.ifi.dbs.elki.database.datastore.DataStoreIDMap; +import de.lmu.ifi.dbs.elki.database.datastore.WritableIntegerDataStore; +import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; + +/** + * 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 ArrayIntegerStore implements WritableIntegerDataStore { + /** + * Data array + */ + private int[] data; + + /** + * DBID to index map + */ + private DataStoreIDMap idmap; + + /** + * Constructor. + * + * @param size Size + * @param idmap ID map + */ + public ArrayIntegerStore(int size, DataStoreIDMap idmap) { + this(size, idmap, 0); + } + + /** + * Constructor. + * + * @param size Size + * @param idmap ID map + * @param def Default value + */ + public ArrayIntegerStore(int size, DataStoreIDMap idmap, int def) { + super(); + this.data = new int[size]; + if (def != 0) { + Arrays.fill(this.data, def); + } + this.idmap = idmap; + } + + @Override + @Deprecated + public Integer get(DBIDRef id) { + try { + return data[idmap.map(id)]; + } + catch(ArrayIndexOutOfBoundsException e) { + return null; + } + } + + @Override + @Deprecated + public Integer put(DBIDRef id, Integer value) { + final int off = idmap.map(id); + int ret = data[off]; + data[off] = value; + return ret; + } + + @Override + public int intValue(DBIDRef id) { + return data[idmap.map(id)]; + } + + @Override + public int putInt(DBIDRef id, int value) { + final int off = idmap.map(id); + final int ret = data[off]; + data[off] = value; + return ret; + } + + @Override + public int put(DBIDRef id, int value) { + final int off = idmap.map(id); + final int 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"; + } +}
\ 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 7be68c97..6e578b61 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 @@ -26,7 +26,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; import de.lmu.ifi.dbs.elki.database.datastore.DataStoreIDMap; 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; +import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; /** * A class to answer representation queries using the stored Array. @@ -73,7 +73,7 @@ public class ArrayRecordStore implements WritableRecordStore { * @return current value */ @SuppressWarnings("unchecked") - protected <T> T get(DBID id, int index) { + protected <T> T get(DBIDRef id, int index) { try { return (T) data[idmap.map(id)][index]; } @@ -97,7 +97,7 @@ public class ArrayRecordStore implements WritableRecordStore { * @return old value */ @SuppressWarnings("unchecked") - protected <T> T set(DBID id, int index, T value) { + protected <T> T set(DBIDRef id, int index, T value) { T ret = (T) data[idmap.map(id)][index]; data[idmap.map(id)][index] = value; return ret; @@ -128,12 +128,12 @@ public class ArrayRecordStore implements WritableRecordStore { @SuppressWarnings("unchecked") @Override - public T get(DBID id) { + public T get(DBIDRef id) { return (T) ArrayRecordStore.this.get(id, index); } @Override - public T put(DBID id, T value) { + public T put(DBIDRef id, T value) { return ArrayRecordStore.this.set(id, index, value); } @@ -143,7 +143,7 @@ public class ArrayRecordStore implements WritableRecordStore { } @Override - public void delete(DBID id) { + public void delete(DBIDRef id) { throw new UnsupportedOperationException("ArrayStore record values cannot be deleted."); } @@ -159,7 +159,7 @@ public class ArrayRecordStore implements WritableRecordStore { } @Override - public boolean remove(DBID id) { + public boolean remove(DBIDRef id) { throw new UnsupportedOperationException("ArrayStore records cannot be removed."); } }
\ No newline at end of file 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 a41a444d..a7ce310b 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 @@ -25,7 +25,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; import de.lmu.ifi.dbs.elki.database.datastore.DataStoreIDMap; import de.lmu.ifi.dbs.elki.database.datastore.WritableDataStore; -import de.lmu.ifi.dbs.elki.database.ids.DBID; +import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; /** * A class to answer representation queries using the stored Array. @@ -58,7 +58,7 @@ public class ArrayStore<T> implements WritableDataStore<T> { @SuppressWarnings("unchecked") @Override - public T get(DBID id) { + public T get(DBIDRef id) { try { return (T) data[idmap.map(id)]; } @@ -74,7 +74,7 @@ public class ArrayStore<T> implements WritableDataStore<T> { } @Override - public T put(DBID id, T value) { + public T put(DBIDRef id, T value) { T ret = get(id); data[idmap.map(id)] = value; return ret; @@ -87,7 +87,7 @@ public class ArrayStore<T> implements WritableDataStore<T> { } @Override - public void delete(DBID id) { + public void delete(DBIDRef id) { throw new UnsupportedOperationException("Can't delete from a static array storage."); } 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 ae06dc00..f9f8d48a 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 @@ -1,4 +1,5 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; + /* This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures @@ -25,7 +26,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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; +import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; /** * Writable data store for double values. @@ -37,25 +38,35 @@ public class MapIntegerDBIDDoubleStore implements WritableDoubleDataStore { * Data storage */ private TIntDoubleMap map; - + /** * Constructor. - * + * * @param size Expected size */ public MapIntegerDBIDDoubleStore(int size) { + this(size, Double.NaN); + } + + /** + * Constructor. + * + * @param size Expected size + * @param def Default value + */ + public MapIntegerDBIDDoubleStore(int size, double def) { super(); - map = new TIntDoubleHashMap(size, 0.5f, Integer.MIN_VALUE, Double.NaN); + map = new TIntDoubleHashMap(size, 0.5f, Integer.MIN_VALUE, def); } @Override @Deprecated - public Double get(DBID id) { + public Double get(DBIDRef id) { return map.get(id.getIntegerID()); } @Override - public double doubleValue(DBID id) { + public double doubleValue(DBIDRef id) { return map.get(id.getIntegerID()); } @@ -71,7 +82,7 @@ public class MapIntegerDBIDDoubleStore implements WritableDoubleDataStore { @Override @Deprecated - public Double put(DBID id, Double value) { + public Double put(DBIDRef id, Double value) { return map.put(id.getIntegerID(), value); } @@ -82,17 +93,17 @@ public class MapIntegerDBIDDoubleStore implements WritableDoubleDataStore { } @Override - public void delete(DBID id) { + public void delete(DBIDRef id) { map.remove(id.getIntegerID()); } @Override - public double putDouble(DBID id, double value) { + public double putDouble(DBIDRef id, double value) { return map.put(id.getIntegerID(), value); } @Override - public double put(DBID id, double value) { + public double put(DBIDRef id, double value) { return map.put(id.getIntegerID(), value); } } 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 new file mode 100644 index 00000000..f7aea633 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/database/datastore/memory/MapIntegerDBIDIntegerStore.java @@ -0,0 +1,109 @@ +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.TIntIntMap; +import gnu.trove.map.hash.TIntIntHashMap; +import de.lmu.ifi.dbs.elki.database.datastore.WritableIntegerDataStore; +import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; + +/** + * Writable data store for double values. + * + * @author Erich Schubert + */ +public class MapIntegerDBIDIntegerStore implements WritableIntegerDataStore { + /** + * Data storage + */ + private TIntIntMap map; + + /** + * Constructor. + * + * @param size Expected size + */ + public MapIntegerDBIDIntegerStore(int size) { + this(size, 0); + } + + /** + * Constructor. + * + * @param size Expected size + * @param def Default value + */ + public MapIntegerDBIDIntegerStore(int size, int def) { + super(); + map = new TIntIntHashMap(size, 0.5f, Integer.MIN_VALUE, def); + } + + @Override + @Deprecated + public Integer get(DBIDRef id) { + return map.get(id.getIntegerID()); + } + + @Override + public int intValue(DBIDRef id) { + return map.get(id.getIntegerID()); + } + + @Override + public String getLongName() { + return "raw"; + } + + @Override + public String getShortName() { + return "raw"; + } + + @Override + @Deprecated + public Integer put(DBIDRef id, Integer value) { + return map.put(id.getIntegerID(), value); + } + + @Override + public void destroy() { + map.clear(); + map = null; + } + + @Override + public void delete(DBIDRef id) { + map.remove(id.getIntegerID()); + } + + @Override + public int putInt(DBIDRef id, int value) { + return map.put(id.getIntegerID(), value); + } + + @Override + public int put(DBIDRef id, int 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 index 8272fb2e..805c6de3 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 @@ -27,7 +27,7 @@ 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; +import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; /** * A class to answer representation queries using a map and an index within the @@ -93,7 +93,7 @@ public class MapIntegerDBIDRecordStore implements WritableRecordStore { * @return current value */ @SuppressWarnings("unchecked") - protected <T> T get(DBID id, int index) { + protected <T> T get(DBIDRef id, int index) { Object[] d = data.get(id.getIntegerID()); if(d == null) { return null; @@ -118,7 +118,7 @@ public class MapIntegerDBIDRecordStore implements WritableRecordStore { * @return previous value */ @SuppressWarnings("unchecked") - protected <T> T set(DBID id, int index, T value) { + protected <T> T set(DBIDRef id, int index, T value) { Object[] d = data.get(id.getIntegerID()); if(d == null) { d = new Object[rlen]; @@ -154,12 +154,12 @@ public class MapIntegerDBIDRecordStore implements WritableRecordStore { @SuppressWarnings("unchecked") @Override - public T get(DBID id) { + public T get(DBIDRef id) { return (T) MapIntegerDBIDRecordStore.this.get(id, index); } @Override - public T put(DBID id, T value) { + public T put(DBIDRef id, T value) { return MapIntegerDBIDRecordStore.this.set(id, index, value); } @@ -169,7 +169,7 @@ public class MapIntegerDBIDRecordStore implements WritableRecordStore { } @Override - public void delete(DBID id) { + public void delete(DBIDRef id) { throw new UnsupportedOperationException("Record storage values cannot be deleted."); } @@ -185,7 +185,7 @@ public class MapIntegerDBIDRecordStore implements WritableRecordStore { } @Override - public boolean remove(DBID id) { + public boolean remove(DBIDRef 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 index 4deb929d..e04027d0 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 @@ -26,7 +26,7 @@ package de.lmu.ifi.dbs.elki.database.datastore.memory; 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; +import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; /** * A class to answer representation queries using a map. Basically, it is just a @@ -70,12 +70,12 @@ public class MapIntegerDBIDStore<T> implements WritableDataStore<T> { } @Override - public T get(DBID id) { + public T get(DBIDRef id) { return data.get(id.getIntegerID()); } @Override - public T put(DBID id, T value) { + public T put(DBIDRef id, T value) { if(value == null) { return data.remove(id.getIntegerID()); } @@ -88,7 +88,7 @@ public class MapIntegerDBIDStore<T> implements WritableDataStore<T> { } @Override - public void delete(DBID id) { + public void delete(DBIDRef id) { data.remove(id.getIntegerID()); } 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 5a98966f..05cf3697 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 @@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentHashMap; 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; +import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; /** * A class to answer representation queries using a map and an index within the @@ -47,6 +48,7 @@ public class MapRecordStore implements WritableRecordStore { /** * Storage Map */ + // TODO: Use trove maps? private final Map<DBID, Object[]> data; /** @@ -84,8 +86,8 @@ public class MapRecordStore implements WritableRecordStore { * @return current value */ @SuppressWarnings("unchecked") - protected <T> T get(DBID id, int index) { - Object[] d = data.get(id); + protected <T> T get(DBIDRef id, int index) { + Object[] d = data.get(id.getDBID()); if(d == null) { return null; } @@ -109,11 +111,11 @@ public class MapRecordStore implements WritableRecordStore { * @return previous value */ @SuppressWarnings("unchecked") - protected <T> T set(DBID id, int index, T value) { - Object[] d = data.get(id); + protected <T> T set(DBIDRef id, int index, T value) { + Object[] d = data.get(id.getDBID()); if(d == null) { d = new Object[rlen]; - data.put(id, d); + data.put(id.getDBID(), d); } T ret = (T) d[index]; d[index] = value; @@ -145,12 +147,12 @@ public class MapRecordStore implements WritableRecordStore { @SuppressWarnings("unchecked") @Override - public T get(DBID id) { + public T get(DBIDRef id) { return (T) MapRecordStore.this.get(id, index); } @Override - public T put(DBID id, T value) { + public T put(DBIDRef id, T value) { return MapRecordStore.this.set(id, index, value); } @@ -160,7 +162,7 @@ public class MapRecordStore implements WritableRecordStore { } @Override - public void delete(DBID id) { + public void delete(DBIDRef id) { throw new UnsupportedOperationException("Record storage values cannot be deleted."); } @@ -176,7 +178,7 @@ public class MapRecordStore implements WritableRecordStore { } @Override - public boolean remove(DBID id) { + public boolean remove(DBIDRef id) { return data.remove(id) != null; } 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 27cd9f63..90742993 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 @@ -28,6 +28,7 @@ import java.util.Map; import de.lmu.ifi.dbs.elki.database.datastore.WritableDataStore; import de.lmu.ifi.dbs.elki.database.ids.DBID; +import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; /** * A class to answer representation queries using a map. Basically, it is just a @@ -41,6 +42,7 @@ public class MapStore<T> implements WritableDataStore<T> { /** * Storage Map */ + // TODO: use trove maps? private Map<DBID, T> data; /** @@ -62,16 +64,16 @@ public class MapStore<T> implements WritableDataStore<T> { } @Override - public T get(DBID id) { - return data.get(id); + public T get(DBIDRef id) { + return data.get(id.getDBID()); } @Override - public T put(DBID id, T value) { + public T put(DBIDRef id, T value) { if(value == null) { - return data.remove(id); + return data.remove(id.getDBID()); } - return data.put(id, value); + return data.put(id.getDBID(), value); } @Override @@ -80,7 +82,7 @@ public class MapStore<T> implements WritableDataStore<T> { } @Override - public void delete(DBID id) { + public void delete(DBIDRef id) { data.remove(id); } 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 3e3ce017..683e4c5d 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 @@ -27,6 +27,7 @@ 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.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; @@ -47,8 +48,15 @@ import de.lmu.ifi.dbs.elki.database.ids.DBIDs; * @apiviz.uses 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 (Double.class.equals(dataclass)) { + return (WritableDataStore<T>) makeDoubleStorage(ids, hints); + } + if (Integer.class.equals(dataclass)) { + return (WritableDataStore<T>) makeIntegerStorage(ids, hints); + } if(ids instanceof DBIDRange) { DBIDRange range = (DBIDRange) ids; Object[] data = new Object[range.size()]; @@ -71,6 +79,39 @@ public class MemoryDataStoreFactory implements DataStoreFactory { } @Override + public WritableDoubleDataStore makeDoubleStorage(DBIDs ids, int hints, double def) { + if(ids instanceof DBIDRange) { + DBIDRange range = (DBIDRange) ids; + return new ArrayDoubleStore(range.size(), new RangeIDMap(range), def); + } + else { + return new MapIntegerDBIDDoubleStore(ids.size(), def); + } + } + + @Override + public WritableIntegerDataStore makeIntegerStorage(DBIDs ids, int hints) { + if(ids instanceof DBIDRange) { + DBIDRange range = (DBIDRange) ids; + return new ArrayIntegerStore(range.size(), new RangeIDMap(range)); + } + else { + return new MapIntegerDBIDIntegerStore(ids.size()); + } + } + + @Override + public WritableIntegerDataStore makeIntegerStorage(DBIDs ids, int hints, int def) { + if(ids instanceof DBIDRange) { + DBIDRange range = (DBIDRange) ids; + return new ArrayIntegerStore(range.size(), new RangeIDMap(range), def); + } + else { + return new MapIntegerDBIDIntegerStore(ids.size(), def); + } + } + + @Override public WritableRecordStore makeRecordStorage(DBIDs ids, int hints, Class<?>... dataclasses) { if(ids instanceof DBIDRange) { DBIDRange range = (DBIDRange) ids; |