Skip to content

Commit a08ace8

Browse files
committed
added full decomposition, scaling unit cell size back
1 parent 6194180 commit a08ace8

4 files changed

Lines changed: 108 additions & 32 deletions

File tree

core/index/src/main/java/mil/nga/giat/geowave/core/index/sfc/hilbert/HilbertSFC.java

Lines changed: 102 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import java.nio.ByteBuffer;
55
import java.util.ArrayList;
66
import java.util.Arrays;
7+
import java.util.LinkedHashMap;
78
import java.util.List;
9+
import java.util.Map;
10+
11+
import com.google.uzaygezen.core.CompactHilbertCurve;
12+
import com.google.uzaygezen.core.MultiDimensionalSpec;
813

914
import mil.nga.giat.geowave.core.index.ByteArrayUtils;
1015
import mil.nga.giat.geowave.core.index.PersistenceUtils;
@@ -13,16 +18,88 @@
1318
import mil.nga.giat.geowave.core.index.sfc.SpaceFillingCurve;
1419
import mil.nga.giat.geowave.core.index.sfc.data.MultiDimensionalNumericData;
1520

16-
import com.google.uzaygezen.core.CompactHilbertCurve;
17-
import com.google.uzaygezen.core.MultiDimensionalSpec;
18-
1921
/***
2022
* Implementation of a Compact Hilbert space filling curve
21-
*
23+
*
2224
*/
2325
public class HilbertSFC implements
2426
SpaceFillingCurve
2527
{
28+
private static class QueryCacheKey
29+
{
30+
private final double[] minsPerDimension;
31+
private final double[] maxesPerDimension;
32+
private final boolean overInclusiveOnEdge;
33+
private final int maxFilteredIndexedRanges;
34+
35+
public QueryCacheKey(
36+
final double[] minsPerDimension,
37+
final double[] maxesPerDimension,
38+
final boolean overInclusiveOnEdge,
39+
final int maxFilteredIndexedRanges ) {
40+
this.minsPerDimension = minsPerDimension;
41+
this.maxesPerDimension = maxesPerDimension;
42+
this.overInclusiveOnEdge = overInclusiveOnEdge;
43+
this.maxFilteredIndexedRanges = maxFilteredIndexedRanges;
44+
}
45+
46+
@Override
47+
public int hashCode() {
48+
final int prime = 31;
49+
int result = 1;
50+
result = (prime * result) + maxFilteredIndexedRanges;
51+
result = (prime * result) + Arrays.hashCode(maxesPerDimension);
52+
result = (prime * result) + Arrays.hashCode(minsPerDimension);
53+
result = (prime * result) + (overInclusiveOnEdge ? 1231 : 1237);
54+
return result;
55+
}
56+
57+
@Override
58+
public boolean equals(
59+
final Object obj ) {
60+
if (this == obj) {
61+
return true;
62+
}
63+
if (obj == null) {
64+
return false;
65+
}
66+
if (getClass() != obj.getClass()) {
67+
return false;
68+
}
69+
final QueryCacheKey other = (QueryCacheKey) obj;
70+
if (maxFilteredIndexedRanges != other.maxFilteredIndexedRanges) {
71+
return false;
72+
}
73+
if (!Arrays.equals(
74+
maxesPerDimension,
75+
other.maxesPerDimension)) {
76+
return false;
77+
}
78+
if (!Arrays.equals(
79+
minsPerDimension,
80+
other.minsPerDimension)) {
81+
return false;
82+
}
83+
if (overInclusiveOnEdge != other.overInclusiveOnEdge) {
84+
return false;
85+
}
86+
return true;
87+
}
88+
}
89+
90+
private static final int MAX_CACHED_QUERIES = 500;
91+
private final Map<QueryCacheKey, RangeDecomposition> queryDecompositionCache = new LinkedHashMap<QueryCacheKey, RangeDecomposition>(
92+
MAX_CACHED_QUERIES + 1,
93+
.75F,
94+
true) {
95+
private static final long serialVersionUID = 1L;
96+
97+
@Override
98+
public boolean removeEldestEntry(
99+
final Map.Entry<QueryCacheKey, RangeDecomposition> eldest ) {
100+
return size() > MAX_CACHED_QUERIES;
101+
}
102+
};
26103
protected CompactHilbertCurve compactHilbertCurve;
27104
protected SFCDimensionDefinition[] dimensionDefinitions;
28105
protected int totalPrecision;
@@ -37,7 +114,7 @@ protected HilbertSFC() {}
37114
/***
38115
* Use the SFCFactory.createSpaceFillingCurve method - don't call this
39116
* constructor directly
40-
*
117+
*
41118
*/
42119
public HilbertSFC(
43120
final SFCDimensionDefinition[] dimensionDefs ) {
@@ -143,14 +220,26 @@ public RangeDecomposition decomposeRange(
143220
if (maxFilteredIndexedRanges == -1) {
144221
maxFilteredIndexedRanges = Integer.MAX_VALUE;
145222
}
146-
return decomposeQueryOperations.decomposeRange(
147-
query.getDataPerDimension(),
148-
compactHilbertCurve,
149-
dimensionDefinitions,
150-
totalPrecision,
151-
maxFilteredIndexedRanges,
152-
REMOVE_VACUUM,
153-
overInclusiveOnEdge);
223+
final QueryCacheKey key = new QueryCacheKey(
224+
query.getMinValuesPerDimension(),
225+
query.getMaxValuesPerDimension(),
226+
overInclusiveOnEdge,
227+
maxFilteredIndexedRanges);
228+
RangeDecomposition rangeDecomp = queryDecompositionCache.get(key);
229+
if (rangeDecomp == null) {
230+
rangeDecomp = decomposeQueryOperations.decomposeRange(
231+
query.getDataPerDimension(),
232+
compactHilbertCurve,
233+
dimensionDefinitions,
234+
totalPrecision,
235+
maxFilteredIndexedRanges,
236+
REMOVE_VACUUM,
237+
overInclusiveOnEdge);
238+
queryDecompositionCache.put(
239+
key,
240+
rangeDecomp);
241+
}
242+
return rangeDecomp;
154243
}
155244

156245
protected static byte[] fitExpectedByteCount(

core/index/src/main/java/mil/nga/giat/geowave/core/index/sfc/hilbert/PrimitiveHilbertSFCOperations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class PrimitiveHilbertSFCOperations implements
4646
{
4747
protected final static long UNIT_CELL_SIZE = (long) Math.pow(
4848
2,
49-
20);
49+
19);
5050
protected long[] binsPerDimension;
5151

5252
protected long minHilbertValue;

core/index/src/main/java/mil/nga/giat/geowave/core/index/sfc/hilbert/UnboundedHilbertSFCOperations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class UnboundedHilbertSFCOperations implements
4646
protected final static BigInteger UNIT_CELL_SIZE = BigDecimal.valueOf(
4747
Math.pow(
4848
2,
49-
20)).toBigInteger();
49+
19)).toBigInteger();
5050
protected BigDecimal[] binsPerDimension;
5151
protected BigInteger minHilbertValue;
5252
protected BigInteger maxHilbertValue;

core/index/src/main/java/mil/nga/giat/geowave/core/index/sfc/tiered/TieredSFCIndexStrategy.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,10 @@ protected static List<ByteArrayRange> getQueryRanges(
121121
maxRangeDecompositionPerBin = (int) Math.ceil((double) maxRanges / (double) binnedQueries.length);
122122
}
123123
for (final BinnedNumericDataset binnedQuery : binnedQueries) {
124-
final RangeDecomposition rangeDecomp;
125-
if (binnedQuery.isFullExtent()) {
126-
rangeDecomp = new RangeDecomposition(
127-
new ByteArrayRange[] {
128-
new ByteArrayRange(
129-
new ByteArrayId(
130-
new byte[] {}),
131-
new ByteArrayId(
132-
new byte[] {}))
133-
});
134-
}
135-
else {
136-
rangeDecomp = sfc.decomposeRange(
137-
binnedQuery,
138-
true,
139-
maxRangeDecompositionPerBin);
140-
}
124+
final RangeDecomposition rangeDecomp = sfc.decomposeRange(
125+
binnedQuery,
126+
true,
127+
maxRangeDecompositionPerBin);
141128
final byte[] tierAndBinId = ByteArrayUtils.combineArrays(
142129
new byte[] {
143130
tier

0 commit comments

Comments
 (0)