Skip to content

Commit

Permalink
Fix numerous warnings (#37)
Browse files Browse the repository at this point in the history
* Fix warnings
  • Loading branch information
tzaeschke authored Jun 22, 2024
1 parent de6a03c commit c4a5ede
Show file tree
Hide file tree
Showing 49 changed files with 273 additions and 233 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ch/ethz/globis/phtree/nv/PhTreeNVSolidF.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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<PHREntry> {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/ethz/globis/phtree/nv/PhTreeVProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public PhTreeVProxy(int dim) {
}

public PhTreeVProxy(PhTree<Object> tree) {
this.tree = (PhTree<Object>) tree;
this.tree = tree;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ch/ethz/globis/phtree/util/BitsInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/ethz/globis/phtree/util/JmxTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/ch/ethz/globis/phtree/util/Refs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -140,7 +141,7 @@ public static <T> T[] arrayCreate(int size) {
* @return Same array or expanded array.
* @param <T> array type
*/
@Deprecated
// TODO remove? was @Deprecated
public static <T> T[] arrayEnsureSize(T[] oldA, int requiredSize) {
if (isCapacitySufficient(oldA, requiredSize)) {
return oldA;
Expand Down Expand Up @@ -177,8 +178,8 @@ public static <T> T[] arrayClone(T[] oldA) {
private static <T> boolean isCapacitySufficient(T[] a, int requiredSize) {
return a.length >= requiredSize;
}
@Deprecated

// TODO remove? was @Deprecated
@SuppressWarnings("unchecked")
public static <T> T[] arrayTrim(T[] oldA, int requiredSize) {
int reqSize = calcArraySize(requiredSize);
Expand All @@ -191,7 +192,7 @@ public static <T> T[] arrayTrim(T[] oldA, int requiredSize) {
return newA;
}

@Deprecated
// TODO remove? was @Deprecated
public static <T> void insertAtPos(T[] values, int pos, T value) {
copyRight(values, pos, values, pos+1, values.length-pos-1);
values[pos] = value;
Expand All @@ -216,8 +217,8 @@ public static <T> 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 <T> void removeAtPos(T[] values, int pos) {
if (pos < values.length-1) {
copyLeft(values, pos+1, values, pos, values.length-pos-1);
Expand Down Expand Up @@ -300,5 +301,14 @@ public static <T> T[] read(ObjectInput in) throws IOException {
}
return ret;
}


@SuppressWarnings("unchecked")
public static <T> T[] newArray(int size) {
return (T[]) new Object[size];
}

@SuppressWarnings("unchecked")
public static <T> T[] newArray(Class<T> c, int size) {
return (T[]) Array.newInstance(c, size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -31,7 +32,8 @@ public class NodeIteratorListReuse<T, R> {

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;


Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();.
Expand All @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/ethz/globis/phtree/v11/PhIteratorNoGC.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();.
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/ch/ethz/globis/phtree/v11/PhTree11.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand All @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ch/ethz/globis/phtree/v11/nt/NtNodePool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -41,7 +42,8 @@ public class NodeIteratorListReuse<T, R> {

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;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();.
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/ethz/globis/phtree/v13/PhIteratorKnn.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public boolean isValid(int bitsToIgnore, long[] prefix) {
}

@Override
public PhKnnQuery<T> reset(int minResults, PhDistance distFn, long[] center) {
public PhKnnQuery<T> reset(int minResults, PhDistance distFn, long ... center) {
this.center = center;
this.distFn = distFn == null ? this.distFn : distFn;
this.currentDistance = Double.MAX_VALUE;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/ethz/globis/phtree/v13/PhIteratorNoGC.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();.
Expand All @@ -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() {
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/ch/ethz/globis/phtree/v13/PhTree13.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,46 +44,46 @@

/**
* n-dimensional index (quad-/oct-/n-tree).
*
* <p>
*
* 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.
*
* <p>
* Version 12: This was an attempt at a persistent version.
*
* <p>
* 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
*
* <p>
* Version 10b: Moved infix into parent node.
*
* <p>
* 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).
*
* <p>
* Version 8b: Extended array pooling to all arrays
*
* <p>
* Version 8: Use 64bit depth everywhere. This should simplify a number of methods, especially
* regarding negative values.
*
* <p>
* Version 7: Uses PhEntry to store/return keys.
*
* <p>
* Version 5: moved postCnt/subCnt into node.
*
* <p>
* Version 4: Using long[] instead of int[]
*
* <p>
* Version 3: This includes values for each key.
*
* <p>
* 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
*
* <p>
* 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
*
* <p>
* See also : T. Zaeschke, C. Zimmerli, M.C. Norrie;
* "The PH-Tree -- A Space-Efficient Storage Structure and Multi-Dimensional Index",
* (SIGMOD 2014)
Expand Down
Loading

0 comments on commit c4a5ede

Please sign in to comment.