diff --git a/.github/codeql-config.yml b/.github/codeql-config.yml index 6c3e97b298..afd23a4c15 100644 --- a/.github/codeql-config.yml +++ b/.github/codeql-config.yml @@ -20,3 +20,5 @@ query-filters: id: java/class-name-matches-super-class # Par, Instance, Factory... - exclude: id: java/comparison-of-identical-expressions # NaN checks +- exclude: + id: java/uncontrolled-arithmetic # many false reports diff --git a/elki-core-data/src/main/java/elki/data/type/MultivariateSeriesTypeInformation.java b/elki-core-data/src/main/java/elki/data/type/MultivariateSeriesTypeInformation.java index fba0f54314..a4c8e116e9 100644 --- a/elki-core-data/src/main/java/elki/data/type/MultivariateSeriesTypeInformation.java +++ b/elki-core-data/src/main/java/elki/data/type/MultivariateSeriesTypeInformation.java @@ -51,7 +51,6 @@ public static > MultivariateSeriesTypeInformation /** * Constructor for an actual type. * - * @param vector type * @param cls base class * @param mindim Minimum dimensionality * @param maxdim Maximum dimensionality diff --git a/elki-gui-minigui/src/main/java/elki/gui/util/ClassTree.java b/elki-gui-minigui/src/main/java/elki/gui/util/ClassTree.java index 725132ee12..cd4d2d6029 100644 --- a/elki-gui-minigui/src/main/java/elki/gui/util/ClassTree.java +++ b/elki-gui-minigui/src/main/java/elki/gui/util/ClassTree.java @@ -180,6 +180,11 @@ public PackageNode(String display, String pkgname) { public String getPackageName() { return pkgname; } + + @Override + public Object clone() { + return super.clone(); // no deep copy necessary + } } /** @@ -217,5 +222,10 @@ public ClassNode(String display, String clsname) { public String getClassName() { return clsname; } + + @Override + public Object clone() { + return super.clone(); // no deep copy necessary + } } } diff --git a/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/AbstractMkTree.java b/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/AbstractMkTree.java index 566a13cf2e..aad972aa1e 100644 --- a/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/AbstractMkTree.java +++ b/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/AbstractMkTree.java @@ -23,6 +23,10 @@ import java.util.HashMap; import java.util.Map; +import elki.database.datastore.DataStore; +import elki.database.datastore.DataStoreFactory; +import elki.database.datastore.DataStoreUtil; +import elki.database.datastore.WritableDataStore; import elki.database.ids.*; import elki.database.query.distance.DistanceQuery; import elki.database.query.knn.KNNSearcher; @@ -105,11 +109,10 @@ public double distance(DBIDRef id1, DBIDRef id2) { * @deprecated Change to use by-object NN lookups instead. */ @Deprecated - protected final Map batchNN(N node, DBIDs ids, int kmax) { - Map res = new HashMap<>(ids.size()); + protected final DataStore batchNN(N node, DBIDs ids, int kmax) { + WritableDataStore res = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_TEMP, KNNList.class); for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) { - DBID id = DBIDUtil.deref(iter); - res.put(id, knnq.getKNN(id, kmax)); + res.put(iter, knnq.getKNN(iter, kmax)); } return res; } diff --git a/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/AbstractMkTreeUnified.java b/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/AbstractMkTreeUnified.java index 71f3e51d44..a2e390ac6a 100644 --- a/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/AbstractMkTreeUnified.java +++ b/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/AbstractMkTreeUnified.java @@ -21,9 +21,8 @@ package elki.index.tree.metrical.mtreevariants.mktrees; import java.util.List; -import java.util.Map; -import elki.database.ids.DBID; +import elki.database.datastore.DataStore; import elki.database.ids.DBIDUtil; import elki.database.ids.KNNList; import elki.database.ids.ModifiableDBIDs; @@ -86,7 +85,7 @@ public void insertAll(List entries) { super.insert(entry, false); } - Map knnLists = batchNN(getNode(getRootID()), ids, settings.kmax); + DataStore knnLists = batchNN(getNode(getRootID()), ids, settings.kmax); kNNdistanceAdjustment(getRootEntry(), knnLists); doExtraIntegrityChecks(); } @@ -97,7 +96,7 @@ public void insertAll(List entries) { * @param entry the root entry of the current subtree * @param knnLists a map of knn lists for each leaf entry */ - protected abstract void kNNdistanceAdjustment(E entry, Map knnLists); + protected abstract void kNNdistanceAdjustment(E entry, DataStore knnLists); /** * Get the value of k_max. diff --git a/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mkapp/MkAppTree.java b/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mkapp/MkAppTree.java index 812538433a..36c746e99b 100644 --- a/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mkapp/MkAppTree.java +++ b/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mkapp/MkAppTree.java @@ -21,19 +21,9 @@ package elki.index.tree.metrical.mtreevariants.mktrees.mkapp; import java.util.List; -import java.util.Map; - -import elki.database.ids.ArrayModifiableDBIDs; -import elki.database.ids.DBID; -import elki.database.ids.DBIDIter; -import elki.database.ids.DBIDRef; -import elki.database.ids.DBIDUtil; -import elki.database.ids.DBIDs; -import elki.database.ids.DoubleDBIDList; -import elki.database.ids.DoubleDBIDListIter; -import elki.database.ids.KNNList; -import elki.database.ids.ModifiableDBIDs; -import elki.database.ids.ModifiableDoubleDBIDList; + +import elki.database.datastore.DataStore; +import elki.database.ids.*; import elki.database.relation.Relation; import elki.index.tree.LeafEntry; import elki.index.tree.metrical.mtreevariants.mktrees.AbstractMkTree; @@ -45,6 +35,7 @@ import elki.utilities.datastructures.heap.Heap; import elki.utilities.datastructures.heap.UpdatableHeap; import elki.utilities.io.ByteArrayUtil; + import net.jafama.FastMath; /** @@ -120,7 +111,7 @@ public void insertAll(List entries) { super.insert(entry, false); } - Map knnLists = batchNN(getNode(getRootID()), ids, settings.kmax + 1); + DataStore knnLists = batchNN(getNode(getRootID()), ids, settings.kmax + 1); adjustApproximatedKNNDistances(getRootEntry(), knnLists); doExtraIntegrityChecks(); @@ -246,7 +237,7 @@ protected void initializeCapacities(MkAppEntry exampleLeaf) { * @param knnLists kNN lists * @return Mean kNN values */ - private double[] getMeanKNNList(DBIDs ids, Map knnLists) { + private double[] getMeanKNNList(DBIDs ids, DataStore knnLists) { double[] means = new double[settings.kmax]; for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) { KNNList knns = knnLists.get(iter); @@ -264,7 +255,7 @@ private double[] getMeanKNNList(DBIDs ids, Map knnLists) { * @param entry the root entry of the current subtree * @param knnLists a map of knn lists for each leaf entry */ - private void adjustApproximatedKNNDistances(MkAppEntry entry, Map knnLists) { + private void adjustApproximatedKNNDistances(MkAppEntry entry, DataStore knnLists) { MkAppTreeNode node = getNode(entry); if(node.isLeaf()) { diff --git a/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mkcop/MkCoPTree.java b/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mkcop/MkCoPTree.java index 10c9fb5fb5..68ed9c8d6f 100644 --- a/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mkcop/MkCoPTree.java +++ b/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mkcop/MkCoPTree.java @@ -22,17 +22,9 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; - -import elki.database.ids.DBID; -import elki.database.ids.DBIDIter; -import elki.database.ids.DBIDRef; -import elki.database.ids.DBIDUtil; -import elki.database.ids.DoubleDBIDList; -import elki.database.ids.DoubleDBIDListIter; -import elki.database.ids.KNNList; -import elki.database.ids.ModifiableDBIDs; -import elki.database.ids.ModifiableDoubleDBIDList; + +import elki.database.datastore.DataStore; +import elki.database.ids.*; import elki.database.relation.Relation; import elki.index.tree.metrical.mtreevariants.mktrees.AbstractMkTree; import elki.index.tree.metrical.mtreevariants.mktrees.MkTreeSettings; @@ -43,7 +35,6 @@ import elki.utilities.exceptions.AbortException; import elki.utilities.io.ByteArrayUtil; import elki.utilities.io.FormatUtil; -import net.jafama.FastMath; /** * MkCopTree is a metrical index structure based on the concepts of the M-Tree @@ -122,7 +113,7 @@ public void insertAll(List entries) { super.insert(entry, false); } - Map knnLists = batchNN(getNode(getRootID()), ids, settings.kmax); + DataStore knnLists = batchNN(getNode(getRootID()), ids, settings.kmax); adjustApproximatedKNNDistances(getRootEntry(), knnLists); doExtraIntegrityChecks(); @@ -147,7 +138,7 @@ public DoubleDBIDList reverseKNNQuery(DBIDRef id, int k) { doReverseKNNQuery(k, id, result, candidates); // refinement of candidates - Map knnLists = batchNN(getNode(getRootID()), candidates, k); + DataStore knnLists = batchNN(getNode(getRootID()), candidates, k); result.sort(); // Collections.sort(candidates); @@ -157,11 +148,10 @@ public DoubleDBIDList reverseKNNQuery(DBIDRef id, int k) { // rkNNStatistics.addTrueHits(result.size()); for(DBIDIter iter = candidates.iter(); iter.valid(); iter.advance()) { - DBID cid = DBIDUtil.deref(iter); - KNNList cands = knnLists.get(cid); + KNNList cands = knnLists.get(iter); for(DoubleDBIDListIter iter2 = cands.iter(); iter2.valid(); iter2.advance()) { if(DBIDUtil.equal(id, iter2)) { - result.add(iter2.doubleValue(), cid); + result.add(iter2.doubleValue(), iter); break; } } @@ -290,9 +280,8 @@ private void doReverseKNNQuery(int k, DBIDRef q, ModifiableDoubleDBIDList result * @param entry the root entry of the current subtree * @param knnLists a map of knn lists for each leaf entry */ - private void adjustApproximatedKNNDistances(MkCoPEntry entry, Map knnLists) { + private void adjustApproximatedKNNDistances(MkCoPEntry entry, DataStore knnLists) { MkCoPTreeNode node = getNode(entry); - if(node.isLeaf()) { for(int i = 0; i < node.getNumEntries(); i++) { MkCoPLeafEntry leafEntry = (MkCoPLeafEntry) node.getEntry(i); @@ -305,7 +294,6 @@ private void adjustApproximatedKNNDistances(MkCoPEntry entry, Map adjustApproximatedKNNDistances(dirEntry, knnLists); } } - ApproximationLine approx = node.conservativeKnnDistanceApproximation(settings.kmax); entry.setConservativeKnnDistanceApproximation(approx); } diff --git a/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mkmax/MkMaxTree.java b/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mkmax/MkMaxTree.java index d8ee3408fa..08508dd0ce 100644 --- a/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mkmax/MkMaxTree.java +++ b/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mkmax/MkMaxTree.java @@ -21,18 +21,9 @@ package elki.index.tree.metrical.mtreevariants.mktrees.mkmax; import java.util.List; -import java.util.Map; - -import elki.database.ids.DBID; -import elki.database.ids.DBIDIter; -import elki.database.ids.DBIDRef; -import elki.database.ids.DBIDUtil; -import elki.database.ids.DoubleDBIDList; -import elki.database.ids.DoubleDBIDListIter; -import elki.database.ids.KNNHeap; -import elki.database.ids.KNNList; -import elki.database.ids.ModifiableDBIDs; -import elki.database.ids.ModifiableDoubleDBIDList; + +import elki.database.datastore.DataStore; +import elki.database.ids.*; import elki.database.relation.Relation; import elki.index.tree.metrical.mtreevariants.mktrees.AbstractMkTreeUnified; import elki.index.tree.metrical.mtreevariants.mktrees.MkTreeSettings; @@ -99,15 +90,14 @@ public DoubleDBIDList reverseKNNQuery(DBIDRef id, int k) { for (DBIDIter candidate = candidates.iter(); candidate.valid(); candidate.advance()) { candidateIDs.add(candidate); } - Map knnLists = batchNN(getNode(getRootID()), candidateIDs, k); + DataStore knnLists = batchNN(getNode(getRootID()), candidateIDs, k); ModifiableDoubleDBIDList result = DBIDUtil.newDistanceDBIDList(); for (DBIDIter iter = candidateIDs.iter(); iter.valid(); iter.advance()) { - DBID cid = DBIDUtil.deref(iter); - KNNList cands = knnLists.get(cid); + KNNList cands = knnLists.get(iter); for (DoubleDBIDListIter iter2 = cands.iter(); iter2.valid(); iter2.advance()) { if (DBIDUtil.equal(id, iter2)) { - result.add(iter2.doubleValue(), cid); + result.add(iter2.doubleValue(), iter); break; } } @@ -134,7 +124,7 @@ protected void preInsert(MkMaxEntry entry) { * Adjusts the knn distance in the subtree of the specified root entry. */ @Override - protected void kNNdistanceAdjustment(MkMaxEntry entry, Map knnLists) { + protected void kNNdistanceAdjustment(MkMaxEntry entry, DataStore knnLists) { MkMaxTreeNode node = getNode(entry); double knnDist_node = 0.; if (node.isLeaf()) { diff --git a/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mktab/MkTabTree.java b/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mktab/MkTabTree.java index 4f6ba344de..bec83a2f8f 100644 --- a/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mktab/MkTabTree.java +++ b/elki-index-mtree/src/main/java/elki/index/tree/metrical/mtreevariants/mktrees/mktab/MkTabTree.java @@ -20,15 +20,8 @@ */ package elki.index.tree.metrical.mtreevariants.mktrees.mktab; -import java.util.Map; - -import elki.database.ids.DBID; -import elki.database.ids.DBIDRef; -import elki.database.ids.DBIDUtil; -import elki.database.ids.DoubleDBIDList; -import elki.database.ids.DoubleDBIDListIter; -import elki.database.ids.KNNList; -import elki.database.ids.ModifiableDoubleDBIDList; +import elki.database.datastore.DataStore; +import elki.database.ids.*; import elki.database.relation.Relation; import elki.index.tree.metrical.mtreevariants.mktrees.AbstractMkTreeUnified; import elki.index.tree.metrical.mtreevariants.mktrees.MkTreeSettings; @@ -131,7 +124,7 @@ protected void initializeCapacities(MkTabEntry exampleLeaf) { } @Override - protected void kNNdistanceAdjustment(MkTabEntry entry, Map knnLists) { + protected void kNNdistanceAdjustment(MkTabEntry entry, DataStore knnLists) { MkTabTreeNode node = getNode(entry); double[] knnDistances_node = initKnnDistanceList(); if(node.isLeaf()) {