diff --git a/CHANGELOG.md b/CHANGELOG.md index b15914a..800e829 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - getStats() for empty trees fails. [#36](https://github.com/tzaeschke/phtree/pull/36) +- Fix some warnings. [#37](https://github.com/tzaeschke/phtree/pull/37) ## 2.8.0 - 2023-07-29 diff --git a/src/main/java/ch/ethz/globis/phtree/nv/PhTreeNVSolidF.java b/src/main/java/ch/ethz/globis/phtree/nv/PhTreeNVSolidF.java index bed086f..b3f2f2a 100644 --- a/src/main/java/ch/ethz/globis/phtree/nv/PhTreeNVSolidF.java +++ b/src/main/java/ch/ethz/globis/phtree/nv/PhTreeNVSolidF.java @@ -169,7 +169,7 @@ public PHREntryIterator queryInclude(double[] lower, double[] upper) { long[] lLow = new long[lower.length << 1]; pre.pre(lower, lower, lLow); pre.pre(upper, upper, lUpp); - return new PHREntryIterator((PhIteratorNV) pht.query(lLow, lUpp), DIM); + return new PHREntryIterator(pht.query(lLow, lUpp), DIM); } /** @@ -183,7 +183,7 @@ public PHREntryIterator queryIntersect(double[] lower, double[] upper) { long[] lLow = new long[lower.length << 1]; pre.pre(MIN, lower, lLow); pre.pre(upper, MAX, lUpp); - return new PHREntryIterator((PhIteratorNV) pht.query(lLow, lUpp), DIM); + return new PHREntryIterator(pht.query(lLow, lUpp), DIM); } public class PHREntryIterator implements Iterator { diff --git a/src/main/java/ch/ethz/globis/phtree/nv/PhTreeVProxy.java b/src/main/java/ch/ethz/globis/phtree/nv/PhTreeVProxy.java index e0ab43e..a4fc5b0 100644 --- a/src/main/java/ch/ethz/globis/phtree/nv/PhTreeVProxy.java +++ b/src/main/java/ch/ethz/globis/phtree/nv/PhTreeVProxy.java @@ -34,7 +34,7 @@ public PhTreeVProxy(int dim) { } public PhTreeVProxy(PhTree tree) { - this.tree = (PhTree) tree; + this.tree = tree; } @Override diff --git a/src/main/java/ch/ethz/globis/phtree/util/BitsInt.java b/src/main/java/ch/ethz/globis/phtree/util/BitsInt.java index 8c87aae..e939026 100644 --- a/src/main/java/ch/ethz/globis/phtree/util/BitsInt.java +++ b/src/main/java/ch/ethz/globis/phtree/util/BitsInt.java @@ -168,7 +168,7 @@ public static void insertBits(int[] ba, final int start, final int nBits) { ba[dstByteStart] = (ba[dstByteStart] & ~mask0) | (Integer.rotateRight(ba[srcByteStart], localShift) & mask0); //write second part - int mask1 = (int) mask0 >>> -srcLocalStart; //(UNIT_BITS-srcLocalStart); + int mask1 = mask0 >>> -srcLocalStart; //(UNIT_BITS-srcLocalStart); ba[dstByteStart] = (ba[dstByteStart] & ~mask1) | ((buf1 >>> localShift) & mask1); } else { //write first part @@ -359,7 +359,7 @@ public static void copyBitsLeft1(int[] src, int posSrc, int[] dst, int posDst, i //TODO? if (localEnd==0) localEnd==32; int leftMask = (int) (dstLocalEnd==0 ? UNIT_0xFF : ~(UNIT_0xFF >>> dstLocalEnd)); // e.g. 1111.1110 int rightMask = (int) (UNIT_0xFF >>> (dstLocalEnd-srcLocalEnd)); - int maskPost = (int) leftMask & rightMask; + int maskPost = leftMask & rightMask; //TODO //TODO local mask should go from dstLocalStart to dstLocalEnd only. //TODO diff --git a/src/main/java/ch/ethz/globis/phtree/util/JmxTools.java b/src/main/java/ch/ethz/globis/phtree/util/JmxTools.java index 7fbb592..a4652fb 100644 --- a/src/main/java/ch/ethz/globis/phtree/util/JmxTools.java +++ b/src/main/java/ch/ethz/globis/phtree/util/JmxTools.java @@ -212,7 +212,8 @@ private static void processNotification(ObjectName name) { totalDiff += mi.diff; totalTime += mi.duration; } - + + @SuppressWarnings("unchecked") public static void gcCheck() { try { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); diff --git a/src/main/java/ch/ethz/globis/phtree/util/Refs.java b/src/main/java/ch/ethz/globis/phtree/util/Refs.java index de7d7c0..efc4157 100644 --- a/src/main/java/ch/ethz/globis/phtree/util/Refs.java +++ b/src/main/java/ch/ethz/globis/phtree/util/Refs.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; +import java.lang.reflect.Array; import java.util.Arrays; import ch.ethz.globis.phtree.PhTreeHelper; @@ -140,7 +141,7 @@ public static T[] arrayCreate(int size) { * @return Same array or expanded array. * @param array type */ - @Deprecated + // TODO remove? was @Deprecated public static T[] arrayEnsureSize(T[] oldA, int requiredSize) { if (isCapacitySufficient(oldA, requiredSize)) { return oldA; @@ -177,8 +178,8 @@ public static T[] arrayClone(T[] oldA) { private static boolean isCapacitySufficient(T[] a, int requiredSize) { return a.length >= requiredSize; } - - @Deprecated + + // TODO remove? was @Deprecated @SuppressWarnings("unchecked") public static T[] arrayTrim(T[] oldA, int requiredSize) { int reqSize = calcArraySize(requiredSize); @@ -191,7 +192,7 @@ public static T[] arrayTrim(T[] oldA, int requiredSize) { return newA; } - @Deprecated + // TODO remove? was @Deprecated public static void insertAtPos(T[] values, int pos, T value) { copyRight(values, pos, values, pos+1, values.length-pos-1); values[pos] = value; @@ -216,8 +217,8 @@ public static T[] insertSpaceAtPos(T[] values, int pos, int requiredSize) { copyRight(values, pos, dst, pos+1, requiredSize-1-pos); return dst; } - - @Deprecated + + // TODO remove? was @Deprecated public static void removeAtPos(T[] values, int pos) { if (pos < values.length-1) { copyLeft(values, pos+1, values, pos, values.length-pos-1); @@ -300,5 +301,14 @@ public static T[] read(ObjectInput in) throws IOException { } return ret; } - + + @SuppressWarnings("unchecked") + public static T[] newArray(int size) { + return (T[]) new Object[size]; + } + + @SuppressWarnings("unchecked") + public static T[] newArray(Class c, int size) { + return (T[]) Array.newInstance(c, size); + } } diff --git a/src/main/java/ch/ethz/globis/phtree/v11/NodeIteratorListReuse.java b/src/main/java/ch/ethz/globis/phtree/v11/NodeIteratorListReuse.java index d202c74..bea6a11 100644 --- a/src/main/java/ch/ethz/globis/phtree/v11/NodeIteratorListReuse.java +++ b/src/main/java/ch/ethz/globis/phtree/v11/NodeIteratorListReuse.java @@ -11,6 +11,7 @@ import ch.ethz.globis.pht64kd.MaxKTreeI.NtEntry; import ch.ethz.globis.phtree.PhEntry; import ch.ethz.globis.phtree.PhTreeHelper; +import ch.ethz.globis.phtree.util.Refs; import ch.ethz.globis.phtree.v11.nt.NtIteratorMask; /** @@ -31,7 +32,8 @@ public class NodeIteratorListReuse { private class PhIteratorStack { @SuppressWarnings("unchecked") - private final NodeIterator[] stack = new NodeIteratorListReuse.NodeIterator[64]; + private final NodeIterator[] stack = + Refs.newArray(NodeIteratorListReuse.NodeIterator.class, 64); private int size = 0; @@ -70,14 +72,9 @@ private final class NodeIterator { /** * - * @param node - * @param dims - * @param valTemplate A null indicates that no values are to be extracted. + * @param node node * @param lower The minimum HC-Pos that a value should have. - * @param upper - * @param minValue The minimum value that any found value should have. - * If the found value is lower, the search continues. - * @param maxValue + * @param upper The maximum HC-Pos that a value should have. */ void reinitAndRun(Node node, long lower, long upper) { this.node = node; diff --git a/src/main/java/ch/ethz/globis/phtree/v11/PhIteratorFullNoGC.java b/src/main/java/ch/ethz/globis/phtree/v11/PhIteratorFullNoGC.java index eb657e7..5db37d4 100644 --- a/src/main/java/ch/ethz/globis/phtree/v11/PhIteratorFullNoGC.java +++ b/src/main/java/ch/ethz/globis/phtree/v11/PhIteratorFullNoGC.java @@ -11,6 +11,7 @@ import ch.ethz.globis.phtree.PhEntry; import ch.ethz.globis.phtree.PhFilter; import ch.ethz.globis.phtree.PhTree.PhExtent; +import ch.ethz.globis.phtree.util.Refs; /** * This PhIterator uses a loop instead of recursion in findNextElement();. @@ -32,7 +33,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") public PhIteratorStack() { - stack = new NodeIteratorFullNoGC[PhTree11.DEPTH_64]; + stack = Refs.newArray(NodeIteratorFullNoGC.class, PhTree11.DEPTH_64); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v11/PhIteratorNoGC.java b/src/main/java/ch/ethz/globis/phtree/v11/PhIteratorNoGC.java index 2f5aad8..06f4bbd 100644 --- a/src/main/java/ch/ethz/globis/phtree/v11/PhIteratorNoGC.java +++ b/src/main/java/ch/ethz/globis/phtree/v11/PhIteratorNoGC.java @@ -12,6 +12,7 @@ import ch.ethz.globis.phtree.PhFilter; import ch.ethz.globis.phtree.PhTree.PhQuery; import ch.ethz.globis.phtree.PhTreeHelper; +import ch.ethz.globis.phtree.util.Refs; /** * This PhIterator uses a loop instead of recursion in findNextElement();. @@ -33,7 +34,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") public PhIteratorStack() { - stack = new NodeIteratorNoGC[PhTree11.DEPTH_64]; + stack = Refs.newArray(NodeIteratorNoGC.class, PhTree11.DEPTH_64); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v11/PhQueryKnnMbbPPList.java b/src/main/java/ch/ethz/globis/phtree/v11/PhQueryKnnMbbPPList.java index a9e2dab..4fd1297 100644 --- a/src/main/java/ch/ethz/globis/phtree/v11/PhQueryKnnMbbPPList.java +++ b/src/main/java/ch/ethz/globis/phtree/v11/PhQueryKnnMbbPPList.java @@ -15,6 +15,7 @@ import ch.ethz.globis.phtree.PhFilterDistance; import ch.ethz.globis.phtree.PhTree.PhExtent; import ch.ethz.globis.phtree.PhTree.PhKnnQuery; +import ch.ethz.globis.phtree.util.Refs; /** * kNN query implementation that uses preprocessors and distance functions. @@ -302,7 +303,7 @@ void reset(int newSize, long[] center) { this.center = center; maxDistance = Double.MAX_VALUE; if (data == null) { - data = new PhEntryDist[newSize]; + data = Refs.newArray(PhEntryDist.class, newSize); distData = new double[newSize]; for (int i = 0; i < data.length; i++) { data[i] = createEntry(); diff --git a/src/main/java/ch/ethz/globis/phtree/v11/PhTree11.java b/src/main/java/ch/ethz/globis/phtree/v11/PhTree11.java index 4ca2833..272aa94 100644 --- a/src/main/java/ch/ethz/globis/phtree/v11/PhTree11.java +++ b/src/main/java/ch/ethz/globis/phtree/v11/PhTree11.java @@ -133,6 +133,9 @@ public int size() { @Override public PhTreeStats getStats() { + if (getRoot() == null) { + return new PhTreeStats(DEPTH_64); + } return getStats(0, getRoot(), new PhTreeStats(DEPTH_64)); } diff --git a/src/main/java/ch/ethz/globis/phtree/v11/nt/NtIteratorMask.java b/src/main/java/ch/ethz/globis/phtree/v11/nt/NtIteratorMask.java index 6a190e3..4ae1b35 100644 --- a/src/main/java/ch/ethz/globis/phtree/v11/nt/NtIteratorMask.java +++ b/src/main/java/ch/ethz/globis/phtree/v11/nt/NtIteratorMask.java @@ -11,6 +11,7 @@ import ch.ethz.globis.pht64kd.MaxKTreeI; import ch.ethz.globis.pht64kd.MaxKTreeI.NtEntry; import ch.ethz.globis.pht64kd.MaxKTreeI.PhIterator64; +import ch.ethz.globis.phtree.util.Refs; /** @@ -34,7 +35,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") public PhIteratorStack(int depth) { - stack = new NtNodeIteratorMask[depth]; + stack = Refs.newArray(NtNodeIteratorMask.class, depth); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v11/nt/NtIteratorMinMax.java b/src/main/java/ch/ethz/globis/phtree/v11/nt/NtIteratorMinMax.java index cf47fdd..cf0b8db 100644 --- a/src/main/java/ch/ethz/globis/phtree/v11/nt/NtIteratorMinMax.java +++ b/src/main/java/ch/ethz/globis/phtree/v11/nt/NtIteratorMinMax.java @@ -11,6 +11,7 @@ import ch.ethz.globis.pht64kd.MaxKTreeI; import ch.ethz.globis.pht64kd.MaxKTreeI.NtEntry; import ch.ethz.globis.pht64kd.MaxKTreeI.PhIterator64; +import ch.ethz.globis.phtree.util.Refs; /** @@ -34,7 +35,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") public PhIteratorStack(int depth) { - stack = new NtNodeIteratorMinMax[depth]; + stack = Refs.newArray(NtNodeIteratorMinMax.class, depth); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v11/nt/NtNodePool.java b/src/main/java/ch/ethz/globis/phtree/v11/nt/NtNodePool.java index bf8225d..1c3bc75 100644 --- a/src/main/java/ch/ethz/globis/phtree/v11/nt/NtNodePool.java +++ b/src/main/java/ch/ethz/globis/phtree/v11/nt/NtNodePool.java @@ -7,6 +7,7 @@ package ch.ethz.globis.phtree.v11.nt; import ch.ethz.globis.phtree.PhTreeHelper; +import ch.ethz.globis.phtree.util.Refs; /** * Manipulation methods and pool for NtNodes. @@ -15,8 +16,8 @@ */ public class NtNodePool { - private static final NtNode[] POOL = - new NtNode[PhTreeHelper.MAX_OBJECT_POOL_SIZE]; + private static final NtNode[] POOL = + Refs.newArray(NtNode.class, PhTreeHelper.MAX_OBJECT_POOL_SIZE); private static int poolSize; /** Nodes currently used outside the pool. */ private static int activeNodes = 0; diff --git a/src/main/java/ch/ethz/globis/phtree/v13/NodeIteratorListReuse.java b/src/main/java/ch/ethz/globis/phtree/v13/NodeIteratorListReuse.java index d8a5c85..4cec934 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13/NodeIteratorListReuse.java +++ b/src/main/java/ch/ethz/globis/phtree/v13/NodeIteratorListReuse.java @@ -22,6 +22,7 @@ import java.util.List; import ch.ethz.globis.phtree.PhEntry; +import ch.ethz.globis.phtree.util.Refs; /** * A NodeIterator that returns a list instead of an Iterator AND reuses the NodeIterator. @@ -41,7 +42,8 @@ public class NodeIteratorListReuse { private class PhIteratorStack { @SuppressWarnings("unchecked") - private final NodeIterator[] stack = new NodeIteratorListReuse.NodeIterator[64]; + private final NodeIterator[] stack = + Refs.newArray(NodeIteratorListReuse.NodeIterator.class,64); private int size = 0; diff --git a/src/main/java/ch/ethz/globis/phtree/v13/PhIteratorFullNoGC.java b/src/main/java/ch/ethz/globis/phtree/v13/PhIteratorFullNoGC.java index 008b939..cc32292 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13/PhIteratorFullNoGC.java +++ b/src/main/java/ch/ethz/globis/phtree/v13/PhIteratorFullNoGC.java @@ -13,6 +13,7 @@ import ch.ethz.globis.phtree.PhEntry; import ch.ethz.globis.phtree.PhFilter; import ch.ethz.globis.phtree.PhTree.PhExtent; +import ch.ethz.globis.phtree.util.Refs; /** * This PhIterator uses a loop instead of recursion in findNextElement();. @@ -34,7 +35,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") PhIteratorStack() { - stack = new NodeIteratorFullNoGC[PhTree13.DEPTH_64]; + stack = Refs.newArray(NodeIteratorFullNoGC.class, PhTree13.DEPTH_64); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v13/PhIteratorKnn.java b/src/main/java/ch/ethz/globis/phtree/v13/PhIteratorKnn.java index cf76b1b..00c47cc 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13/PhIteratorKnn.java +++ b/src/main/java/ch/ethz/globis/phtree/v13/PhIteratorKnn.java @@ -66,7 +66,7 @@ public boolean isValid(int bitsToIgnore, long[] prefix) { } @Override - public PhKnnQuery reset(int minResults, PhDistance distFn, long[] center) { + public PhKnnQuery reset(int minResults, PhDistance distFn, long ... center) { this.center = center; this.distFn = distFn == null ? this.distFn : distFn; this.currentDistance = Double.MAX_VALUE; diff --git a/src/main/java/ch/ethz/globis/phtree/v13/PhIteratorNoGC.java b/src/main/java/ch/ethz/globis/phtree/v13/PhIteratorNoGC.java index 21258d7..ff0ed1f 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13/PhIteratorNoGC.java +++ b/src/main/java/ch/ethz/globis/phtree/v13/PhIteratorNoGC.java @@ -14,6 +14,7 @@ import ch.ethz.globis.phtree.PhFilter; import ch.ethz.globis.phtree.PhTree.PhQuery; import ch.ethz.globis.phtree.PhTreeHelper; +import ch.ethz.globis.phtree.util.Refs; /** * This PhIterator uses a loop instead of recursion in findNextElement();. @@ -35,7 +36,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") PhIteratorStack() { - stack = new NodeIteratorNoGC[PhTree13.DEPTH_64]; + stack = Refs.newArray(NodeIteratorNoGC.class, PhTree13.DEPTH_64); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v13/PhTree13.java b/src/main/java/ch/ethz/globis/phtree/v13/PhTree13.java index 1e2ad93..9833f69 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13/PhTree13.java +++ b/src/main/java/ch/ethz/globis/phtree/v13/PhTree13.java @@ -44,46 +44,46 @@ /** * n-dimensional index (quad-/oct-/n-tree). - * + *

* * Version 13: * Version 13SP: Based on Version 11. Some optimizations, for example store HC-Pos in postFix. * Version 13SP has 'synchronized' object pools and NT nodes for high dim. * Version 13 has local unsynchronized pools. It also has the NT tree removed. - * + *

* Version 12: This was an attempt at a persistent version. - * + *

* Version 11: Use of NtTree for Nodes * 'null' values are replaced by NULL, this allows removal of AHC-exists bitmap * Removal of recursion (and reimplementation) for get/insert/delete/update - * + *

* Version 10b: Moved infix into parent node. - * + *

* Version 10: Store sub-nodes and postfixes in a common structure (one list/HC of key, one array) * Advantages: much easier iteration through node, replacement of sub/post during * updates w/o bit shifting, can check infix without accessing sub-node (good for I/O). - * + *

* Version 8b: Extended array pooling to all arrays - * + *

* Version 8: Use 64bit depth everywhere. This should simplify a number of methods, especially * regarding negative values. - * + *

* Version 7: Uses PhEntry to store/return keys. - * + *

* Version 5: moved postCnt/subCnt into node. - * + *

* Version 4: Using long[] instead of int[] - * + *

* Version 3: This includes values for each key. - * + *

* Storage: * - classic: One node per combination of bits. Unused nodes can be cut off. * - use prefix-truncation: a node may contain a series of unique bit combinations - * + *

* Hypercube: expanded byte array that contains 2^DIM references to sub-nodes (and posts, depending * on implementation) * Linearization: Storing Hypercube as paired array of index / non_null_reference - * + *

* See also : T. Zaeschke, C. Zimmerli, M.C. Norrie; * "The PH-Tree -- A Space-Efficient Storage Structure and Multi-Dimensional Index", * (SIGMOD 2014) diff --git a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/Node.java b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/Node.java index e6a40c0..1841eaa 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/Node.java +++ b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/Node.java @@ -146,7 +146,7 @@ PhEntry createNodeEntry(long[] key, T value) { return new PhEntry<>(key, value); } - private void discardNode(PhTree13SP tree) { + private void discardNode() { Bits.arrayReplace(ba, null); Refs.arrayReplace(values, null); entryCnt = 0; @@ -539,7 +539,7 @@ private Object deleteAndMergeIntoParent(int pinToDelete, long hcPos, long[] key, parent.replaceSubWithPost(pinInParent, posInParent, newPost, val2); } - discardNode(tree); + discardNode(); return valueToDelete; } @@ -575,7 +575,7 @@ private void mergeIntoParentNt(long[] key, Node parent, PhTree13SP tree) { parent.replaceSubWithPost(pinInParent, posInParent, nte.getKdKey(), nte.getValue()); } - discardNode(tree); + discardNode(); } /** diff --git a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/NodeIteratorListReuse.java b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/NodeIteratorListReuse.java index 10c18a6..e936869 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/NodeIteratorListReuse.java +++ b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/NodeIteratorListReuse.java @@ -10,6 +10,7 @@ import ch.ethz.globis.pht64kd.MaxKTreeI.NtEntry; import ch.ethz.globis.phtree.PhEntry; +import ch.ethz.globis.phtree.util.Refs; import ch.ethz.globis.phtree.v13SynchedPool.nt.NtIteratorMask; import java.util.List; @@ -32,7 +33,8 @@ public class NodeIteratorListReuse { private class PhIteratorStack { @SuppressWarnings("unchecked") - private final NodeIterator[] stack = new NodeIteratorListReuse.NodeIterator[64]; + private final NodeIterator[] stack = + Refs.newArray(NodeIteratorListReuse.NodeIterator.class, 64); private int size = 0; diff --git a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhIteratorFullNoGC.java b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhIteratorFullNoGC.java index ab80264..3fb4d15 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhIteratorFullNoGC.java +++ b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhIteratorFullNoGC.java @@ -11,6 +11,7 @@ import ch.ethz.globis.phtree.PhEntry; import ch.ethz.globis.phtree.PhFilter; import ch.ethz.globis.phtree.PhTree.PhExtent; +import ch.ethz.globis.phtree.util.Refs; import java.util.NoSuchElementException; @@ -34,7 +35,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") public PhIteratorStack() { - stack = new NodeIteratorFullNoGC[PhTree13SP.DEPTH_64]; + stack = Refs.newArray(NodeIteratorFullNoGC.class, PhTree13SP.DEPTH_64); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhIteratorNoGC.java b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhIteratorNoGC.java index 344de1b..14346d0 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhIteratorNoGC.java +++ b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhIteratorNoGC.java @@ -12,6 +12,7 @@ import ch.ethz.globis.phtree.PhFilter; import ch.ethz.globis.phtree.PhTree.PhQuery; import ch.ethz.globis.phtree.PhTreeHelper; +import ch.ethz.globis.phtree.util.Refs; import java.util.NoSuchElementException; @@ -35,7 +36,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") public PhIteratorStack() { - stack = new NodeIteratorNoGC[PhTree13SP.DEPTH_64]; + stack = Refs.newArray(NodeIteratorNoGC.class, PhTree13SP.DEPTH_64); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhQueryKnnMbbPPList.java b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhQueryKnnMbbPPList.java index ab6214c..c7f2eea 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhQueryKnnMbbPPList.java +++ b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhQueryKnnMbbPPList.java @@ -304,7 +304,7 @@ void reset(int newSize, long[] center) { this.center = center; maxDistance = Double.MAX_VALUE; if (data == null) { - data = new PhEntryDist[newSize]; + data = (PhEntryDist[]) new Object[newSize]; distData = new double[newSize]; for (int i = 0; i < data.length; i++) { data[i] = createEntry(); diff --git a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhTree13SP.java b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhTree13SP.java index 1044e88..7b8ca38 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhTree13SP.java +++ b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/PhTree13SP.java @@ -31,45 +31,45 @@ /** * n-dimensional index (quad-/oct-/n-tree). - * + *

* Version 13: * Version 13SP: Based on Version 11. Some optimizations, for example store HC-Pos in postFix. * Version 13SP has 'synchronized' object pools and NT nodes for high dim. * Version 13 has local unsynchronized pools. It also has the NT tree removed. - * + *

* Version 12: This was an attempt at a persistent version. - * + *

* Version 11: Use of NtTree for Nodes * 'null' values are replaced by NULL, this allows removal of AHC-exists bitmap * Removal of recursion (and reimplementation) for get/insert/delete/update - * + *

* Version 10b: Moved infix into parent node. - * + *

* Version 10: Store sub-nodes and postfixes in a common structure (one list/HC of key, one array) * Advantages: much easier iteration through node, replacement of sub/post during * updates w/o bit shifting, can check infix without accessing sub-node (good for I/O). - * + *

* Version 8b: Extended array pooling to all arrays - * + *

* Version 8: Use 64bit depth everywhere. This should simplify a number of methods, especially * regarding negative values. - * + *

* Version 7: Uses PhEntry to store/return keys. - * + *

* Version 5: moved postCnt/subCnt into node. - * + *

* Version 4: Using long[] instead of int[] - * + *

* Version 3: This includes values for each key. - * + *

* Storage: * - classic: One node per combination of bits. Unused nodes can be cut off. * - use prefix-truncation: a node may contain a series of unique bit combinations - * + *

* Hypercube: expanded byte array that contains 2^DIM references to sub-nodes (and posts, depending * on implementation) * Linearization: Storing Hypercube as paired array of index / non_null_reference - * + *

* See also : T. Zaeschke, C. Zimmerli, M.C. Norrie; * "The PH-Tree -- A Space-Efficient Storage Structure and Multi-Dimensional Index", * (SIGMOD 2014) @@ -139,6 +139,9 @@ public int size() { @Override public PhTreeStats getStats() { + if (getRoot() == null) { + return new PhTreeStats(DEPTH_64); + } return getStats(0, getRoot(), new PhTreeStats(DEPTH_64)); } diff --git a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/nt/NtIteratorMask.java b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/nt/NtIteratorMask.java index f3d440a..24dac6b 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/nt/NtIteratorMask.java +++ b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/nt/NtIteratorMask.java @@ -11,6 +11,7 @@ import ch.ethz.globis.pht64kd.MaxKTreeI; import ch.ethz.globis.pht64kd.MaxKTreeI.NtEntry; import ch.ethz.globis.pht64kd.MaxKTreeI.PhIterator64; +import ch.ethz.globis.phtree.util.Refs; import java.util.NoSuchElementException; @@ -36,7 +37,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") public PhIteratorStack(int depth) { - stack = new NtNodeIteratorMask[depth]; + stack = Refs.newArray(NtNodeIteratorMask.class, depth); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/nt/NtIteratorMinMax.java b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/nt/NtIteratorMinMax.java index 0f2ee35..ddfc089 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/nt/NtIteratorMinMax.java +++ b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/nt/NtIteratorMinMax.java @@ -11,6 +11,7 @@ import ch.ethz.globis.pht64kd.MaxKTreeI; import ch.ethz.globis.pht64kd.MaxKTreeI.NtEntry; import ch.ethz.globis.pht64kd.MaxKTreeI.PhIterator64; +import ch.ethz.globis.phtree.util.Refs; import java.util.NoSuchElementException; @@ -36,7 +37,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") public PhIteratorStack(int depth) { - stack = new NtNodeIteratorMinMax[depth]; + stack = Refs.newArray(NtNodeIteratorMinMax.class, depth); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/nt/NtNodePool.java b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/nt/NtNodePool.java index c3f342b..c346e7e 100644 --- a/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/nt/NtNodePool.java +++ b/src/main/java/ch/ethz/globis/phtree/v13SynchedPool/nt/NtNodePool.java @@ -9,6 +9,7 @@ package ch.ethz.globis.phtree.v13SynchedPool.nt; import ch.ethz.globis.phtree.PhTreeHelper; +import ch.ethz.globis.phtree.util.Refs; /** * Manipulation methods and pool for NtNodes. @@ -16,9 +17,9 @@ * @author ztilmann */ public class NtNodePool { - + private static final NtNode[] POOL = - new NtNode[PhTreeHelper.MAX_OBJECT_POOL_SIZE]; + Refs.newArray(NtNode.class, PhTreeHelper.MAX_OBJECT_POOL_SIZE); private static int poolSize; /** Nodes currently used outside the pool. */ private static int activeNodes = 0; diff --git a/src/main/java/ch/ethz/globis/phtree/v16/NodeIteratorListReuse.java b/src/main/java/ch/ethz/globis/phtree/v16/NodeIteratorListReuse.java index e7eb257..8d9e303 100644 --- a/src/main/java/ch/ethz/globis/phtree/v16/NodeIteratorListReuse.java +++ b/src/main/java/ch/ethz/globis/phtree/v16/NodeIteratorListReuse.java @@ -22,6 +22,7 @@ import java.util.List; import ch.ethz.globis.phtree.PhEntry; +import ch.ethz.globis.phtree.util.Refs; import ch.ethz.globis.phtree.v16.Node.BSTEntry; import ch.ethz.globis.phtree.v16.bst.BSTIteratorMask; @@ -43,7 +44,8 @@ public class NodeIteratorListReuse { private class PhIteratorStack { @SuppressWarnings("unchecked") - private final NodeIterator[] stack = new NodeIteratorListReuse.NodeIterator[64]; + private final NodeIterator[] stack = + Refs.newArray(NodeIteratorListReuse.NodeIterator.class, 64); private int size = 0; diff --git a/src/main/java/ch/ethz/globis/phtree/v16/PhIteratorFullNoGC.java b/src/main/java/ch/ethz/globis/phtree/v16/PhIteratorFullNoGC.java index 5efa772..5daf210 100644 --- a/src/main/java/ch/ethz/globis/phtree/v16/PhIteratorFullNoGC.java +++ b/src/main/java/ch/ethz/globis/phtree/v16/PhIteratorFullNoGC.java @@ -24,6 +24,7 @@ import ch.ethz.globis.phtree.PhEntry; import ch.ethz.globis.phtree.PhFilter; import ch.ethz.globis.phtree.PhTree.PhExtent; +import ch.ethz.globis.phtree.util.Refs; import ch.ethz.globis.phtree.util.unsynced.LongArrayOps; /** @@ -46,7 +47,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") PhIteratorStack() { - stack = new NodeIteratorFullNoGC[PhTree16.DEPTH_64]; + stack = Refs.newArray(NodeIteratorFullNoGC.class, PhTree16.DEPTH_64); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v16/PhIteratorKnn.java b/src/main/java/ch/ethz/globis/phtree/v16/PhIteratorKnn.java index c1cc69b..ab357a8 100644 --- a/src/main/java/ch/ethz/globis/phtree/v16/PhIteratorKnn.java +++ b/src/main/java/ch/ethz/globis/phtree/v16/PhIteratorKnn.java @@ -64,7 +64,7 @@ public boolean isValid(int bitsToIgnore, long[] prefix) { } @Override - public PhKnnQuery reset(int minResults, PhDistance distFn, long[] center) { + public PhKnnQuery reset(int minResults, PhDistance distFn, long ... center) { this.center = center; this.distFn = distFn == null ? this.distFn : distFn; this.currentDistance = Double.MAX_VALUE; diff --git a/src/main/java/ch/ethz/globis/phtree/v16/PhIteratorNoGC.java b/src/main/java/ch/ethz/globis/phtree/v16/PhIteratorNoGC.java index 3946816..ef4f416 100644 --- a/src/main/java/ch/ethz/globis/phtree/v16/PhIteratorNoGC.java +++ b/src/main/java/ch/ethz/globis/phtree/v16/PhIteratorNoGC.java @@ -25,6 +25,7 @@ import ch.ethz.globis.phtree.PhFilter; import ch.ethz.globis.phtree.PhTree.PhQuery; import ch.ethz.globis.phtree.PhTreeHelper; +import ch.ethz.globis.phtree.util.Refs; import ch.ethz.globis.phtree.util.unsynced.LongArrayOps; /** @@ -47,7 +48,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") PhIteratorStack() { - stack = new NodeIteratorNoGC[PhTree16.DEPTH_64]; + stack = Refs.newArray(NodeIteratorNoGC.class, PhTree16.DEPTH_64); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v16/PhTree16.java b/src/main/java/ch/ethz/globis/phtree/v16/PhTree16.java index 376ce4f..f8d16f3 100644 --- a/src/main/java/ch/ethz/globis/phtree/v16/PhTree16.java +++ b/src/main/java/ch/ethz/globis/phtree/v16/PhTree16.java @@ -43,48 +43,48 @@ /** * n-dimensional index (quad-/oct-/n-tree). - * + *

* Version 16: BST-only, directly integrated with Node - * + *

* Version 15: BST-Only - * + *

* Version 14: Removed NT (nested tree) and replaced it with hierarchical table. - * + *

* Version 13: Based on Version 11. Some optimizations, for example store HC-Pos in postFix. - * + *

* Version 12: This was an attempt at a persistent version. - * + *

* Version 11: Use of NtTree for Nodes * 'null' values are replaced by NULL, this allows removal of AHC-exists bitmap * Removal of recursion (and reimplementation) for get/insert/delete/update - * + *

* Version 10b: Moved infix into parent node. - * + *

* Version 10: Store sub-nodes and postfixes in a common structure (one list/HC of key, one array) * Advantages: much easier iteration through node, replacement of sub/post during * updates w/o bit shifting, can check infix without accessing sub-node (good for I/O). - * + *

* Version 8b: Extended array pooling to all arrays - * + *

* Version 8: Use 64bit depth everywhere. This should simplify a number of methods, especially * regarding negative values. - * + *

* Version 7: Uses PhEntry to store/return keys. - * + *

* Version 5: moved postCnt/subCnt into node. - * + *

* Version 4: Using long[] instead of int[] - * + *

* Version 3: This includes values for each key. - * + *

* Storage: * - classic: One node per combination of bits. Unused nodes can be cut off. * - use prefix-truncation: a node may contain a series of unique bit combinations - * + *

* Hypercube: expanded byte array that contains 2^DIM references to sub-nodes (and posts, depending * on implementation) * Linearization: Storing Hypercube as paired array of index / non_null_reference - * + *

* See also : T. Zaeschke, C. Zimmerli, M.C. Norrie; * "The PH-Tree -- A Space-Efficient Storage Structure and Multi-Dimensional Index", * (SIGMOD 2014) diff --git a/src/main/java/ch/ethz/globis/phtree/v16hd/NodeIteratorListReuse.java b/src/main/java/ch/ethz/globis/phtree/v16hd/NodeIteratorListReuse.java index ad50693..4fe03b0 100644 --- a/src/main/java/ch/ethz/globis/phtree/v16hd/NodeIteratorListReuse.java +++ b/src/main/java/ch/ethz/globis/phtree/v16hd/NodeIteratorListReuse.java @@ -42,7 +42,7 @@ public class NodeIteratorListReuse { private class PhIteratorStack { @SuppressWarnings("unchecked") - private final NodeIterator[] stack = new NodeIteratorListReuse.NodeIterator[64]; + private final NodeIterator[] stack = (NodeIteratorListReuse.NodeIterator[]) new Object[64]; private int size = 0; diff --git a/src/main/java/ch/ethz/globis/phtree/v16hd/PhIteratorFullNoGC.java b/src/main/java/ch/ethz/globis/phtree/v16hd/PhIteratorFullNoGC.java index f5a208e..c1f711e 100644 --- a/src/main/java/ch/ethz/globis/phtree/v16hd/PhIteratorFullNoGC.java +++ b/src/main/java/ch/ethz/globis/phtree/v16hd/PhIteratorFullNoGC.java @@ -23,6 +23,7 @@ import ch.ethz.globis.phtree.PhEntry; import ch.ethz.globis.phtree.PhFilter; import ch.ethz.globis.phtree.PhTree.PhExtent; +import ch.ethz.globis.phtree.util.Refs; import ch.ethz.globis.phtree.util.unsynced.LongArrayOps; /** @@ -45,7 +46,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") PhIteratorStack() { - stack = new NodeIteratorFullNoGC[PhTree16HD.DEPTH_64]; + stack = Refs.newArray(NodeIteratorFullNoGC.class, PhTree16HD.DEPTH_64); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v16hd/PhIteratorKnn.java b/src/main/java/ch/ethz/globis/phtree/v16hd/PhIteratorKnn.java index c53e8dc..a533ff0 100644 --- a/src/main/java/ch/ethz/globis/phtree/v16hd/PhIteratorKnn.java +++ b/src/main/java/ch/ethz/globis/phtree/v16hd/PhIteratorKnn.java @@ -64,7 +64,7 @@ public boolean isValid(int bitsToIgnore, long[] prefix) { } @Override - public PhKnnQuery reset(int minResults, PhDistance distFn, long[] center) { + public PhKnnQuery reset(int minResults, PhDistance distFn, long ... center) { this.center = center; this.distFn = distFn == null ? this.distFn : distFn; this.currentDistance = Double.MAX_VALUE; diff --git a/src/main/java/ch/ethz/globis/phtree/v16hd/PhIteratorNoGC.java b/src/main/java/ch/ethz/globis/phtree/v16hd/PhIteratorNoGC.java index fcec9af..86363a7 100644 --- a/src/main/java/ch/ethz/globis/phtree/v16hd/PhIteratorNoGC.java +++ b/src/main/java/ch/ethz/globis/phtree/v16hd/PhIteratorNoGC.java @@ -24,6 +24,7 @@ import ch.ethz.globis.phtree.PhFilter; import ch.ethz.globis.phtree.PhTree.PhQuery; import ch.ethz.globis.phtree.PhTreeHelper; +import ch.ethz.globis.phtree.util.Refs; import ch.ethz.globis.phtree.util.unsynced.LongArrayOps; /** @@ -46,7 +47,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") PhIteratorStack() { - stack = new NodeIteratorNoGC[PhTree16HD.DEPTH_64]; + stack = Refs.newArray(NodeIteratorNoGC.class, PhTree16HD.DEPTH_64); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v16hd/PhTree16HD.java b/src/main/java/ch/ethz/globis/phtree/v16hd/PhTree16HD.java index dfbbc61..162944d 100644 --- a/src/main/java/ch/ethz/globis/phtree/v16hd/PhTree16HD.java +++ b/src/main/java/ch/ethz/globis/phtree/v16hd/PhTree16HD.java @@ -47,48 +47,48 @@ /** * n-dimensional index (quad-/oct-/n-tree). - * + *

* Version 16: BST-only, directly integrated with Node - * + *

* Version 15: BST-Only - * + *

* Version 14: Removed NT (nested tree) and replaced it with hierarchical table. - * + *

* Version 13: Based on Version 11. Some optimizations, for example store HC-Pos in postFix. - * + *

* Version 12: This was an attempt at a persistent version. - * + *

* Version 11: Use of NtTree for Nodes * 'null' values are replaced by NULL, this allows removal of AHC-exists bitmap * Removal of recursion (and reimplementation) for get/insert/delete/update - * + *

* Version 10b: Moved infix into parent node. - * + *

* Version 10: Store sub-nodes and postfixes in a common structure (one list/HC of key, one array) * Advantages: much easier iteration through node, replacement of sub/post during * updates w/o bit shifting, can check infix without accessing sub-node (good for I/O). - * + *

* Version 8b: Extended array pooling to all arrays - * + *

* Version 8: Use 64bit depth everywhere. This should simplify a number of methods, especially * regarding negative values. - * + *

* Version 7: Uses PhEntry to store/return keys. - * + *

* Version 5: moved postCnt/subCnt into node. - * + *

* Version 4: Using long[] instead of int[] - * + *

* Version 3: This includes values for each key. - * + *

* Storage: * - classic: One node per combination of bits. Unused nodes can be cut off. * - use prefix-truncation: a node may contain a series of unique bit combinations - * + *

* Hypercube: expanded byte array that contains 2^DIM references to sub-nodes (and posts, depending * on implementation) * Linearization: Storing Hypercube as paired array of index / non_null_reference - * + *

* See also : T. Zaeschke, C. Zimmerli, M.C. Norrie; * "The PH-Tree -- A Space-Efficient Storage Structure and Multi-Dimensional Index", * (SIGMOD 2014) diff --git a/src/main/java/ch/ethz/globis/phtree/v8/Node.java b/src/main/java/ch/ethz/globis/phtree/v8/Node.java index 04aea5b..a79ae6a 100644 --- a/src/main/java/ch/ethz/globis/phtree/v8/Node.java +++ b/src/main/java/ch/ethz/globis/phtree/v8/Node.java @@ -78,11 +78,11 @@ private static final boolean NI_THRESHOLD(int subCnt, int postCnt) { protected Node(Node original, int dim) { if (original.subNRef != null) { int size = original.subNRef.length; - this.subNRef = new Node[size]; + this.subNRef = (Node[]) new Object[size]; System.arraycopy(original.subNRef, 0, this.subNRef, 0, size); } if (original.values != null) { - this.values = (T[]) original.values.clone(); + this.values = original.values.clone(); } if (original.ba != null) { this.ba = new long[original.ba.length]; @@ -283,7 +283,7 @@ void addSubNode(long pos, Node sub, final int DIM) { } if (subNRef == null) { - subNRef = new Node[2]; + subNRef = Refs.newArray(Node.class, 2); } //decide here whether to use hyper-cube or linear representation @@ -298,7 +298,7 @@ void addSubNode(long pos, Node sub, final int DIM) { //switch to normal array (full hyper-cube) if applicable. if (DIM<=31 && (REF_BITS+SIK_WIDTH(DIM))*(subNRef.length+1L) >= REF_BITS*(1L<[] na = new Node[1<[] na = Refs.newArray(Node.class, 1< sub, final int DIM) { if (subNRef.length < bufSubCount+1) { int newLen = bufSubCount+1; newLen = (newLen&1)==0 ? newLen : newLen+1; //ensure multiples of two - Node[] na2 = new Node[newLen]; + Node[] na2 = Refs.newArray(Node.class, newLen); System.arraycopy(subNRef, 0, na2, 0, start); System.arraycopy(subNRef, start, na2, start+1, len); subNRef = na2; @@ -409,7 +409,7 @@ void removeSub(long pos, final int DIM) { int prePostBits_SubLHC = getBitPos_PostIndex(DIM); int bia2Size = calcArraySizeTotalBits(bufPostCnt, DIM); long[] bia2 = Bits.arrayCreate(bia2Size); - Node[] sa2 = new Node[bufSubCnt]; + Node[] sa2 = Refs.newArray(Node.class, bufSubCnt); int preSubBits = getBitPos_SubNodeIndex(DIM); //Copy only bits that are relevant. Otherwise we might mess up the not-null table! Bits.copyBitsLeft(ba, 0, bia2, 0, preSubBits); @@ -460,7 +460,7 @@ void removeSub(long pos, final int DIM) { int newLen = bufSubCnt-1; newLen = (newLen&1)==0 ? newLen : newLen+1; //ensure multiples of two if (newLen > 0) { - Node[] na2 = new Node[newLen]; + Node[] na2 = Refs.newArray(Node.class, newLen); System.arraycopy(subNRef, 0, na2, 0, p2); System.arraycopy(subNRef, p2+1, na2, p2, len); subNRef = na2; @@ -487,8 +487,9 @@ void removeSub(long pos, final int DIM) { /** * Compare two post-fixes. Takes as parameter not the position but the post-offset-bits. - * @param pob - * @param key + * @param offsPostKey offsPostKey + * @param hcPos hcPos + * @param key key * @return true, if the post-fixes match */ boolean postEqualsPOB(int offsPostKey, long hcPos, long[] key) { @@ -589,6 +590,7 @@ void addPost(long pos, long[] key, T value) { * @param offsPostKey POB: Post offset bits from getPostOffsetBits(...) * @param key */ + @SuppressWarnings("deprecated") void addPostPOB(long pos, int offsPostKey, long[] key, T value) { final int DIM = key.length; final int bufSubCnt = getSubCount(); @@ -614,7 +616,7 @@ void addPostPOB(long pos, int offsPostKey, long[] key, T value) { //switch representation (HC <-> Linear)? //+1 bit for null/not-null flag - long sizeHC = (long) ((DIM * postLen + PINN_HC_WIDTH) * (1L << DIM)); + long sizeHC = (DIM * postLen + PINN_HC_WIDTH) * (1L << DIM); //+DIM because every index entry needs DIM bits long sizeLin = (DIM * postLen + PIK_WIDTH(DIM)) * (bufPostCnt+1L); if (!isPostHC() && (DIM<=31) && (sizeLin >= sizeHC)) { @@ -773,8 +775,6 @@ void niBuild(int bufSubCnt, int bufPostCnt, int DIM) { /** * - * @param bufSubCnt - * @param bufPostCnt * @param DIM * @param posToRemove * @param removeSub Remove sub or post? @@ -815,7 +815,7 @@ T niDeconstruct(int DIM, long posToRemove, boolean removeSub) { //switch to normal array (full hyper-cube) if applicable. if (DIM<=31 && (REF_BITS+SIK_WIDTH(DIM))*newSubCnt >= REF_BITS*(1L<[] na = new Node[1<[] na = Refs.newArray(Node.class, 1<> it = ind.iterator(); while (it.hasNext()) { Entry> e = it.nextEntry(); @@ -830,7 +830,7 @@ T niDeconstruct(int DIM, long posToRemove, boolean removeSub) { setSubHC( false ); int bia2Size = calcArraySizeTotalBits(newPostCnt, DIM); long[] bia2 = Bits.arrayCreate(bia2Size); - Node[] sa2 = new Node[newSubCnt]; + Node[] sa2 = Refs.newArray(Node.class, newSubCnt); int preSubBits = getBitPos_SubNodeIndex(DIM); //Copy only bits that are relevant. Otherwise we might mess up the not-null table! Bits.copyBitsLeft(ba, 0, bia2, 0, preSubBits); @@ -954,10 +954,12 @@ T getPostPOB(int offsPostKey, long pos, long[] key) { /** * Get post-fix. - * @param offsPostKey - * @param key - * @param range After the method call, this contains the postfix if the postfix matches the - * range. Otherwise it contains only part of the postfix. + * @param offsPostKey offsPostKey + * @param hcPos hcPos + * @param key key + * @param rangeMin After the method call, this contains the postfix if the postfix matches + * the range. Otherwise it contains only part of the postfix. + * @param rangeMax rangeMax * @return NodeEntry if the postfix matches the range, otherwise null. * @Deprecated Use next method instead. */ @@ -985,10 +987,12 @@ NodeEntry getPostPOB(int offsPostKey, long hcPos, long[] key, /** * Get post-fix. - * @param offsPostKey - * @param key - * @param range After the method call, this contains the postfix if the postfix matches the + * @param offsPostKey offsPostKey + * @param hcPos hcPos + * @param e entry + * @param rangeMin After the method call, this contains the postfix if the postfix matches the * range. Otherwise it contains only part of the postfix. + * @param rangeMax rangeMax * @return NodeEntry if the postfix matches the range, otherwise null. */ boolean getPostPOB(int offsPostKey, long hcPos, PhEntry e, @@ -1042,12 +1046,18 @@ NodeEntry getPostPOB_E(int offsPostKey, long hcPos, long[] key) { /** * Get post-fix. - * @param offsPostKey - * @param key - * @param range After the method call, this contains the postfix if the postfix matches the - * range. Otherwise it contains only part of the postfix. + * @param offsPostKey offsPostKey + * @param hcPos hcPos + * @param DIM dim + * @param valTemplate valTemplate + * @param rangeMin After the method call, this contains the postfix if the postfix matches + * the range. Otherwise it contains only part of the postfix. + * @param rangeMax rangeMax + * @param minToCheck minToCheck + * @param maxToCheck maxToCheck * @return true, if the postfix matches the range. */ + @SuppressWarnings("unchecked") PhEntry getPostPOB(int offsPostKey, long hcPos, int DIM, long[] valTemplate, long[] rangeMin, long[] rangeMax, int[] minToCheck, int[] maxToCheck) { if (DEBUG && ind != null) { @@ -1120,6 +1130,7 @@ PhEntry getPostPOB(int offsPostKey, long hcPos, int DIM, long[] valTemplate, /** * Same as above, but without checks. */ + @SuppressWarnings("unchecked") PhEntry getPostPOBNoCheck(int offsPostKey, long hcPos, int DIM, long[] valTemplate, long[] rangeMin, long[] rangeMax) { if (DEBUG && ind != null) { @@ -1209,6 +1220,7 @@ T getPost(long pos, long[] key) { } + @SuppressWarnings("deprecated") T removePostPOB(long pos, int offsPostKey, final int DIM) { final int bufPostCnt = getPostCount(); final int bufSubCnt = getSubCount(); @@ -1428,14 +1440,6 @@ int getBitPos_Infix() { return HC_BITS;// + DIM+1 + DIM+1; } - /** - * - * @param offs - * @param pos - * @param DIM - * @param bufSubCnt use -1 to have it calculated by this method - * @return - */ private int offs2ValPos(int offs, long pos, int DIM) { if (isPostHC()) { return (int) pos; @@ -1451,8 +1455,8 @@ private int offs2ValPos(int offs, long pos, int DIM) { /** * - * @param pos - * @param DIM + * @param pos position + * @param DIM dim * @return The position (in bits) of the postfix VALUE. For LHC, the key is stored * directly before the value. */ diff --git a/src/main/java/ch/ethz/globis/phtree/v8/NodeIteratorListReuse.java b/src/main/java/ch/ethz/globis/phtree/v8/NodeIteratorListReuse.java index 2381a72..88f13f1 100644 --- a/src/main/java/ch/ethz/globis/phtree/v8/NodeIteratorListReuse.java +++ b/src/main/java/ch/ethz/globis/phtree/v8/NodeIteratorListReuse.java @@ -8,6 +8,7 @@ import java.util.ArrayList; +import ch.ethz.globis.phtree.util.Refs; import org.zoodb.index.critbit.CritBit64.Entry; import org.zoodb.index.critbit.CritBit64.QueryIteratorMask; @@ -34,7 +35,8 @@ public class NodeIteratorListReuse { public class PhIteratorStack { @SuppressWarnings("unchecked") - private final NodeIterator[] stack = new NodeIteratorListReuse.NodeIterator[64]; + private final NodeIterator[] stack = + Refs.newArray(NodeIteratorListReuse.NodeIterator.class, 64); private int size = 0; @@ -94,14 +96,9 @@ private final class NodeIterator { /** * - * @param node - * @param DIM - * @param valTemplate A null indicates that no values are to be extracted. + * @param node node * @param lower The minimum HC-Pos that a value should have. - * @param upper - * @param minValue The minimum value that any found value should have. If the found value is - * lower, the search continues. - * @param maxValue + * @param upper The maximum HC-Pos that a value should have. */ void reinitAndRun(Node node, long lower, long upper) { this.node = node; diff --git a/src/main/java/ch/ethz/globis/phtree/v8/PhIteratorFullNoGC.java b/src/main/java/ch/ethz/globis/phtree/v8/PhIteratorFullNoGC.java index 65cf0a6..0d471fc 100644 --- a/src/main/java/ch/ethz/globis/phtree/v8/PhIteratorFullNoGC.java +++ b/src/main/java/ch/ethz/globis/phtree/v8/PhIteratorFullNoGC.java @@ -12,6 +12,7 @@ import ch.ethz.globis.phtree.PhFilter; import ch.ethz.globis.phtree.PhTreeHelper; import ch.ethz.globis.phtree.PhTree.PhExtent; +import ch.ethz.globis.phtree.util.Refs; /** * This PhIterator uses a loop instead of recursion in findNextElement();. @@ -33,7 +34,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") public PhIteratorStack() { - stack = new NodeIteratorFullNoGC[PhTree8.DEPTH_64]; + stack = Refs.newArray(NodeIteratorFullNoGC.class, PhTree8.DEPTH_64); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v8/PhIteratorNoGC.java b/src/main/java/ch/ethz/globis/phtree/v8/PhIteratorNoGC.java index f1a81ca..abc0ad0 100644 --- a/src/main/java/ch/ethz/globis/phtree/v8/PhIteratorNoGC.java +++ b/src/main/java/ch/ethz/globis/phtree/v8/PhIteratorNoGC.java @@ -12,6 +12,7 @@ import ch.ethz.globis.phtree.PhFilter; import ch.ethz.globis.phtree.PhTreeHelper; import ch.ethz.globis.phtree.PhTree.PhQuery; +import ch.ethz.globis.phtree.util.Refs; /** * This PhIterator uses a loop instead of recursion in findNextElement();. @@ -33,7 +34,7 @@ private class PhIteratorStack { @SuppressWarnings("unchecked") public PhIteratorStack() { - stack = new NodeIteratorNoGC[PhTree8.DEPTH_64]; + stack = Refs.newArray(NodeIteratorNoGC.class, PhTree8.DEPTH_64); } public boolean isEmpty() { diff --git a/src/main/java/ch/ethz/globis/phtree/v8/PhTree8.java b/src/main/java/ch/ethz/globis/phtree/v8/PhTree8.java index 21f48ce..3065dc0 100644 --- a/src/main/java/ch/ethz/globis/phtree/v8/PhTree8.java +++ b/src/main/java/ch/ethz/globis/phtree/v8/PhTree8.java @@ -155,6 +155,9 @@ public int size() { @Override public PhTreeStats getStats() { + if (getRoot() == null) { + return new PhTreeStats(DEPTH_64); + } return getQuality(0, getRoot(), new PhTreeStats(DEPTH_64)); } diff --git a/src/main/java/org/zoodb/index/critbit/CritBit.java b/src/main/java/org/zoodb/index/critbit/CritBit.java index 988316a..5db58cf 100644 --- a/src/main/java/org/zoodb/index/critbit/CritBit.java +++ b/src/main/java/org/zoodb/index/critbit/CritBit.java @@ -19,54 +19,54 @@ /** * CritBit is a multi-dimensional OR arbitrary length crit-bit tree. - * + *

* Cribit trees are very space efficient due to prefix-sharing and suitable for * multi-dimensional data with low dimensionality (e.g. less than 10 dimensions or so). * They are also stable, that means unlike kD-trees or quadtrees they do not require * rebalancing, this makes update performance much more predictable. - * + *

* There is 1 1D-version and a kD-version (kD: k-dimensional). * The 1D version supports keys with arbitrary length (e.g. 256bit), the kD-version * supports k-dimensional keys with a maximum length of 64 bit per dimension. - * + *

* Both tree versions use internally the same methods, except for the range queries. * For range queries, the 1D version interprets the parameters as one minimum and one * maximum value. For kD queries, the parameters are interpreted as arrays of * minimum and maximum values (i.e. the low left and upper right * corner of a query (hyper-)rectangle). - * + *

* All method ending with 'KD' are for k-dimensional use of the tree, all other methods are for * 1-dimensional use. Exceptions are the size(), printTree() and similar methods, which work for * all dimensions. - * + *

* In order to store floating point values, please convert them to 'long' with * BitTools.toSortableLong(...), also when supplying query parameters. * Extracted values can be converted back with BitTools.toDouble() or toFloat(). - * + *

* Version 1.3.5 * - Fixed rare problem with postfix creation. This solves a problem * with kd-queries and slightly reduces memory consumption. - * + *

* Version 1.3.2 * - Added QueryIterator.reset() - * + *

* Version 1.3.1 * - Fixed issue #3 where iterators won't work with 'null' as values. - * + *

* Version 1.2.2 * - Moved tests to tst folder - * + *

* Version 1.2.1 * - Replaced compare() with isEqual() where possible * - Simplified compare(), doesInfixMatch() * - Removed unused arguments - * + *

* Version 1.2 * - Added iterator() to iterate over all entries - * + *

* Version 1.1 * - Slight performance improvements in mergeLong() and readAndSplit() - * + *

* Version 1.0 * - Initial release * @@ -136,7 +136,7 @@ public static CritBit1D create1D(int width) { throw new IllegalArgumentException("Illegal bit width: " + width); } // SINGLE_DIM ensures that DIM is never used in this case. - return new CritBit(width, SINGLE_DIM); + return new CritBit<>(width, SINGLE_DIM); } /** @@ -154,7 +154,7 @@ public static CritBitKD createKD(int width, int dim) { if (dim < 1) { throw new IllegalArgumentException("Illegal dimension count: " + dim); } - return new CritBit(width, dim); + return new CritBit<>(width, dim); } /** @@ -200,7 +200,7 @@ private V putNoCheck(long[] key, V val) { if (posDiff < n.posDiff && posDiff != -1) { long[] subInfix = extractInfix(currentPrefix, posDiff+1, n.posDiff-1); //new sub-node - Node newSub = new Node(posDiff+1, n.loPost, n.loVal, n.hiPost, n.hiVal, + Node newSub = new Node<>(posDiff+1, n.loPost, n.loVal, n.hiPost, n.hiVal, subInfix, n.posDiff); newSub.hi = n.hi; newSub.lo = n.lo; @@ -365,8 +365,8 @@ private boolean checkNode(Node n, int firstBitOfNode) { /** * Creates a postfix starting at posDiff+1. - * @param val - * @param posDiff + * @param val val + * @param posDiff posDiff * @return the postfix. */ private long[] createPostFix(long[] val, int posDiff) { @@ -391,9 +391,9 @@ private Node createNode(long[] k1, V val1, long[] k2, V val2, int posFirstBit long[] p2 = createPostFix(k2, posDiff); //if (isABitwiseSmallerB(v1, v2)) { if (BitTools.getBit(k2, posDiff)) { - return new Node(posFirstBit, p1, val1, p2, val2, infix, posDiff); + return new Node<>(posFirstBit, p1, val1, p2, val2, infix, posDiff); } else { - return new Node(posFirstBit, p2, val2, p1, val1, infix, posDiff); + return new Node<>(posFirstBit, p2, val2, p1, val1, infix, posDiff); } } @@ -439,9 +439,9 @@ private static long[] extractInfix(long[] v, int startPos, int endPos) { } /** - * + * @param n node * @param v key - * @param startPos start position + * @param currentVal currentVal * @return True if the infix matches the value or if no infix is defined */ private boolean doesInfixMatch(Node n, long[] v, long[] currentVal) { @@ -736,7 +736,7 @@ private void updateParentAfterRemove(Node parent, long[] newPost, V newVal, @Override public FullIterator iterator() { checkDim0(); - return new FullIterator(this, DEPTH); + return new FullIterator<>(this, DEPTH); } public static class FullIterator implements Iterator { @@ -752,10 +752,10 @@ public static class FullIterator implements Iterator { private int stackTop = -1; @SuppressWarnings("unchecked") - public FullIterator(CritBit cb, int DEPTH) { - this.stack = new Node[DEPTH]; - this.readHigherNext = new byte[DEPTH]; // default = false - int intArrayLen = (DEPTH+63) >>> 6; + public FullIterator(CritBit cb, int depth) { + this.stack = (Node[]) new Object[depth]; + this.readHigherNext = new byte[depth]; // default = false + int intArrayLen = (depth+63) >>> 6; this.valIntTemplate = new long[intArrayLen]; if (cb.rootKey != null) { @@ -821,8 +821,8 @@ private void findNext() { /** * Full comparison on the parameter. Assigns the parameter to 'nextVal' if comparison * fits. - * @param keyTemplate - * @param value + * @param keyTemplate keyTemplate + * @param value value */ private void readNextVal(long[] keyTemplate, V value) { nextValue = value; @@ -857,7 +857,7 @@ public Entry nextEntry() { if (!hasNext()) { throw new NoSuchElementException(); } - Entry ret = new Entry(nextKey, nextValue); + Entry ret = new Entry<>(nextKey, nextValue); findNext(); return ret; } @@ -872,7 +872,7 @@ public void remove() { @Override public QueryIterator query(long[] min, long[] max) { checkDim0(); - return new QueryIterator(this, min, max); + return new QueryIterator<>(this, min, max); } public static class QueryIterator implements Iterator { @@ -889,12 +889,13 @@ public static class QueryIterator implements Iterator { private static final byte RETURN_TO_PARENT = 2; private final byte[] readHigherNext; private int stackTop = -1; - private final boolean[] loEnclosed, hiEnclosed; + private final boolean[] loEnclosed; + private final boolean[] hiEnclosed; @SuppressWarnings("unchecked") QueryIterator(CritBit cb, long[] minOrig, long[] maxOrig) { this.cb = cb; - this.stack = new Node[cb.DEPTH]; + this.stack = (Node[]) new Object[cb.DEPTH]; this.readHigherNext = new byte[cb.DEPTH]; // default = false int intArrayLen = (cb.DEPTH+63) >>> 6; this.valIntTemplate = new long[intArrayLen]; @@ -981,7 +982,7 @@ private void findNext() { /** * Comparison on the post-fix. Assigns the parameter to 'nextVal' if comparison fits. - * @param keyTemplate + * @param keyTemplate keyTemplate * @return Whether we have a match or not */ private boolean checkMatchIntoNextVal(long[] keyTemplate, int startBit, V value) { @@ -1094,7 +1095,7 @@ public Entry nextEntry() { if (!hasNext()) { throw new NoSuchElementException(); } - Entry ret = new Entry(nextKey, nextValue); + Entry ret = new Entry<>(nextKey, nextValue); findNext(); return ret; } @@ -1127,15 +1128,15 @@ public static class QueryIteratorWithMask implements Iterator { private final long MAX_MASK; @SuppressWarnings("unchecked") - public QueryIteratorWithMask(CritBit cb, long[] minOrig, long[] maxOrig, int DIM) { + public QueryIteratorWithMask(CritBit cb, long[] minOrig, long[] maxOrig, int dim) { this.cb = cb; - this.stack = new Node[cb.DEPTH]; + this.stack = (Node[]) new Object[cb.DEPTH]; this.readHigherNext = new byte[cb.DEPTH]; // default = false int intArrayLen = (cb.DEPTH+63) >>> 6; this.valIntTemplate = new long[intArrayLen]; this.domMaskLo = new long[intArrayLen]; this.domMaskHi = new long[intArrayLen]; - this.MAX_MASK = ~((-1L) << DIM); + this.MAX_MASK = ~((-1L) << dim); reset(minOrig, maxOrig); } @@ -1222,7 +1223,7 @@ private void findNext() { /** * Comparison on the post-fix. Assigns the parameter to 'nextVal' if comparison fits. - * @param keyTemplate + * @param keyTemplate keyTemplate * @return Whether we have a match or not */ private boolean checkMatchIntoNextVal(long[] keyTemplate, int startBit, V value) { @@ -1449,7 +1450,7 @@ public Entry nextEntry() { if (!hasNext()) { throw new NoSuchElementException(); } - Entry ret = new Entry(nextKey, nextValue); + Entry ret = new Entry<>(nextKey, nextValue); findNext(); return ret; } @@ -1488,7 +1489,7 @@ public static class CheckEmptyWithMask { */ public CheckEmptyWithMask(CritBit cb, int dims) { this.cb = cb; - this.stack = new Node[cb.DEPTH]; + this.stack = (Node[]) new Object[cb.DEPTH]; this.readHigherNext = new byte[cb.DEPTH]; // default = false int intArrayLen = (cb.DEPTH+63) >>> 6; this.valIntTemplate = new long[intArrayLen]; @@ -1585,7 +1586,7 @@ private boolean findNext() { /** * Comparison on the post-fix. Assigns the parameter to 'nextVal' if comparison fits. - * @param keyTemplate + * @param keyTemplate keyTemplate * @return Whether we have a match or not */ private boolean checkMatchIntoNextVal(long[] keyTemplate, int startBit) { @@ -1885,7 +1886,7 @@ private void checkDIM(long[] key) { public QueryIteratorKD queryKD(long[] min, long[] max) { checkDIM(min); checkDIM(max); - return new QueryIteratorKD(this, min, max, DIM, DEPTH); + return new QueryIteratorKD<>(this, min, max, DIM, DEPTH); } public static class QueryIteratorKD implements Iterator { @@ -1908,16 +1909,16 @@ public static class QueryIteratorKD implements Iterator { private int stackTop = -1; @SuppressWarnings("unchecked") - public QueryIteratorKD(CritBit cb, long[] minOrig, long[] maxOrig, int DIM, int DEPTH) { - this.stack = new Node[DIM*DEPTH]; - this.readHigherNext = new byte[DIM*DEPTH]; // default = false - this.keyOrigTemplate = new long[DIM]; + public QueryIteratorKD(CritBit cb, long[] minOrig, long[] maxOrig, int dim, int depth) { + this.stack = (Node[]) new Object[dim*depth]; + this.readHigherNext = new byte[dim*depth]; // default = false + this.keyOrigTemplate = new long[dim]; this.minOrig = minOrig; this.maxOrig = maxOrig; - this.DIM = DIM; - this.DIM_INV_16 = 1 + ((1<<16)+1)/DIM; - this.DEPTH = DEPTH; - this.DEPTH_OFFS = 64-DEPTH; //the shift local to any Long + this.DIM = dim; + this.DIM_INV_16 = 1 + ((1<<16)+1)/dim; + this.DEPTH = depth; + this.DEPTH_OFFS = 64-depth; //the shift local to any Long if (cb.rootKey != null) { readPostFixAndSplit(cb.rootKey, 0, keyOrigTemplate); @@ -2003,7 +2004,7 @@ private void unsetBitAfterSplit(long[] keyOrigTemplate, int posBitInt) { /** * Full comparison on the parameter. Assigns the parameter to 'nextKey' if comparison * fits. - * @param keyTemplate + * @param keyOrigTemplate keyOrigTemplate * @return Whether we have a match or not */ private boolean checkMatchOrigKDFullIntoNextVal(long[] keyOrigTemplate, V value) { @@ -2075,9 +2076,8 @@ private boolean checkMatchOrigKD(long[] keyOrigTemplate, int currentDepth) { /** * - * @param n - * @param infixStart The bit-position of the first infix bits relative to the whole value - * @param currentPrefix + * @param n node + * @param currentPrefixOrig currentPrefixOrig */ private void readAndSplitInfix(Node n, long[] currentPrefixOrig) { if (n.infix == null) { @@ -2092,11 +2092,11 @@ private void readPostFixAndSplit(long[] postVal, int posFirstBit, long[] current } /** - * - * @param src Interleaved src array + * QUESTIONS: TZ: hack: I fixed the javadoc errors without checking if the javadoc is correct! + * @param srcVal Interleaved(?) src array * @param posFirstBit First bit to be transferred * @param stopBit Stop bit (last bit to be transferred + 1) - * @param dst Non-interleaved destination array + * @param dstVal Non-interleaved(?) destination array */ private void readAndSplit(long[] srcVal, int posFirstBit, long stopBit, long[] dstVal) { long maskSrc = 0x8000000000000000L >>> (posFirstBit & 0x3F); @@ -2126,7 +2126,7 @@ private void readAndSplit(long[] srcVal, int posFirstBit, long stopBit, long[] d /** * Calculate the common minimum depth across all dimensions. * This is equal to {@code floor(posDirstBit/DIM)}. - * @param posFirstBit + * @param posFirstBit posFirstBit * @return depth across dims. */ private int getDepthAcrossDims(int posFirstBit) { @@ -2162,7 +2162,7 @@ public Entry nextEntry() { if (!hasNext()) { throw new NoSuchElementException(); } - Entry ret = new Entry(nextKey, nextValue); + Entry ret = new Entry<>(nextKey, nextValue); findNext(); return ret; } diff --git a/src/main/java/org/zoodb/index/critbit/CritBit64.java b/src/main/java/org/zoodb/index/critbit/CritBit64.java index d38488c..f0b4f25 100644 --- a/src/main/java/org/zoodb/index/critbit/CritBit64.java +++ b/src/main/java/org/zoodb/index/critbit/CritBit64.java @@ -55,6 +55,8 @@ * * @author Tilmann Zaeschke */ +import ch.ethz.globis.phtree.util.Refs; + import java.util.Iterator; import java.util.NoSuchElementException; @@ -331,9 +333,9 @@ private static long extractPrefix(long v, int endPos) { } /** - * + * @param posDiff posDIff * @param v key - * @param startPos start position + * @param prefix prefix * @return True if the prefix matches the value or if no prefix is defined */ private boolean doesPrefixMatch(int posDiff, long v, long prefix) { @@ -533,7 +535,7 @@ public static class CBIterator implements Iterator { @SuppressWarnings("unchecked") public CBIterator() { - this.stack = new Node[DEPTH]; + this.stack = Refs.newArray(Node.class, DEPTH); this.readHigherNext = new byte[DEPTH]; // default = false } @@ -664,7 +666,7 @@ public static class QueryIterator implements Iterator { @SuppressWarnings("unchecked") public QueryIterator() { - this.stack = new Node[DEPTH]; + this.stack = (Node[]) new Object[DEPTH]; this.readHigherNext = new byte[DEPTH]; // default = false this.prefixes = new long[DEPTH]; } @@ -844,7 +846,7 @@ public static class QueryIteratorMask implements Iterator { @SuppressWarnings("unchecked") public QueryIteratorMask() { - this.stack = new Node[DEPTH]; + this.stack = Refs.newArray(Node.class, DEPTH); this.readHigherNext = new byte[DEPTH]; // default = false this.prefixes = new long[DEPTH]; } diff --git a/src/test/java/ch/ethz/globis/phtree/bits/TestBitsByte.java b/src/test/java/ch/ethz/globis/phtree/bits/TestBitsByte.java index 0aa3f8d..1745447 100644 --- a/src/test/java/ch/ethz/globis/phtree/bits/TestBitsByte.java +++ b/src/test/java/ch/ethz/globis/phtree/bits/TestBitsByte.java @@ -350,7 +350,7 @@ private void checkBinarySearch(byte[] ba, int key) { private void check(byte[] t, long ... ints) { for (int i = 0; i < ints.length; i++) { assertEquals("i=" + i + " " + Bits.toBinary(ints, 8) + " / " + - BitsByte.toBinary(t), (byte)ints[i], (byte)t[i]); + BitsByte.toBinary(t), (byte)ints[i], t[i]); } } diff --git a/src/test/java/ch/ethz/globis/phtree/bits/TestBitsShort.java b/src/test/java/ch/ethz/globis/phtree/bits/TestBitsShort.java index 2349f3b..5afa9ca 100644 --- a/src/test/java/ch/ethz/globis/phtree/bits/TestBitsShort.java +++ b/src/test/java/ch/ethz/globis/phtree/bits/TestBitsShort.java @@ -430,14 +430,14 @@ private void checkBinarySearch(short[] ba, int key) { private void check(short[] t, long ... ints) { for (int i = 0; i < ints.length; i++) { assertEquals("i=" + i + " | " + BitsShort.toBinary(ints, 16) + " / " + - BitsShort.toBinary(t), (short)ints[i], (short)t[i]); + BitsShort.toBinary(t), (short)ints[i], t[i]); } } private void check(short[] t, short[] s) { for (int i = 0; i < s.length; i++) { assertEquals("i=" + i + " | " + BitsShort.toBinary(s) + " / " + - BitsShort.toBinary(t), (short)s[i], (short)t[i]); + BitsShort.toBinary(t), s[i], t[i]); } } diff --git a/src/test/java/ch/ethz/globis/phtree/bst/TestNT.java b/src/test/java/ch/ethz/globis/phtree/bst/TestNT.java index 3bdc52e..849d118 100644 --- a/src/test/java/ch/ethz/globis/phtree/bst/TestNT.java +++ b/src/test/java/ch/ethz/globis/phtree/bst/TestNT.java @@ -36,7 +36,7 @@ public void testBSTree() { //lookup for (int i = 0; i < N; i++) { int x = ht.get(i, out); - assertEquals("i=" + i, i+100, (int) x); + assertEquals("i=" + i, i+100, x); //if (i%1000 == 0) System.out.println("lu=" + i); } diff --git a/src/test/java/ch/ethz/globis/phtree/test/util/TestUtil.java b/src/test/java/ch/ethz/globis/phtree/test/util/TestUtil.java index 0d0c7a1..9d43284 100644 --- a/src/test/java/ch/ethz/globis/phtree/test/util/TestUtil.java +++ b/src/test/java/ch/ethz/globis/phtree/test/util/TestUtil.java @@ -69,16 +69,13 @@ public static void beforeTest(Object[] args) { /** * Do we need this? - * @deprecated do not use */ public static void afterTest() { getInstance().afterTest(); } - /** * Do we need this? - * @deprecated do not use */ public static void beforeClass() { getInstance().beforeClass(); @@ -86,16 +83,13 @@ public static void beforeClass() { /** * Do we need this? - * @deprecated do not use */ public static void afterClass() { getInstance().afterClass(); } - /** * Do we need this? - * @deprecated do not use */ public static void beforeSuite() { getInstance().beforeSuite();