use of com.google.uzaygezen.core.ZoomingSpaceVisitorAdapter in project geowave by locationtech.
the class UnboundedHilbertSFCOperations method decomposeRange.
@Override
public RangeDecomposition decomposeRange(final NumericData[] rangePerDimension, final CompactHilbertCurve compactHilbertCurve, final SFCDimensionDefinition[] dimensionDefinitions, final int totalPrecision, final int maxFilteredIndexedRanges, final boolean removeVacuum, final boolean overInclusiveOnEdge) {
// List of query range minimum
// and
// maximum
// values
final List<BigInteger> minRangeList = new ArrayList<>();
final List<BigInteger> maxRangeList = new ArrayList<>();
final BigIntegerContent zero = new BigIntegerContent(BigInteger.valueOf(0L));
final List<BigIntegerRange> region = new ArrayList<>(dimensionDefinitions.length);
for (int d = 0; d < dimensionDefinitions.length; d++) {
final BigInteger normalizedMin = normalizeDimension(dimensionDefinitions[d], rangePerDimension[d].getMin(), binsPerDimension[d], true, overInclusiveOnEdge);
BigInteger normalizedMax = normalizeDimension(dimensionDefinitions[d], rangePerDimension[d].getMax(), binsPerDimension[d], false, overInclusiveOnEdge);
if (normalizedMin.compareTo(normalizedMax) > 0) {
// if they're both equal, which is possible because we treat max
// as exclusive, set bin max to bin min (ie. treat it as
// inclusive in this case)
normalizedMax = normalizedMin;
}
minRangeList.add(normalizedMin);
maxRangeList.add(normalizedMax);
region.add(BigIntegerRange.of(normalizedMin, normalizedMax.add(BigInteger.ONE)));
}
final BigInteger minQuadSize = getMinimumQuadSize(minRangeList, maxRangeList);
final RegionInspector<BigIntegerRange, BigIntegerContent> regionInspector = SimpleRegionInspector.create(ImmutableList.of(region), new BigIntegerContent(minQuadSize), Functions.<BigIntegerRange>identity(), BigIntegerRangeHome.INSTANCE, zero);
final PlainFilterCombiner<BigIntegerRange, BigInteger, BigIntegerContent, BigIntegerRange> intervalCombiner = new PlainFilterCombiner<>(BigIntegerRange.of(0, 1));
final QueryBuilder<BigIntegerRange, BigIntegerRange> queryBuilder = BacktrackingQueryBuilder.create(regionInspector, intervalCombiner, maxFilteredIndexedRanges, removeVacuum, BigIntegerRangeHome.INSTANCE, zero);
synchronized (compactHilbertCurve) {
compactHilbertCurve.accept(new ZoomingSpaceVisitorAdapter(compactHilbertCurve, queryBuilder));
}
// com.google.uzaygezen.core.Query<LongRange, LongRange> hilbertQuery =
// queryBuilder.get();
final List<FilteredIndexRange<BigIntegerRange, BigIntegerRange>> hilbertRanges = queryBuilder.get().getFilteredIndexRanges();
final ByteArrayRange[] sfcRanges = new ByteArrayRange[hilbertRanges.size()];
final int expectedByteCount = (int) Math.ceil(totalPrecision / 8.0);
if (expectedByteCount <= 0) {
// special case for no precision
return new RangeDecomposition(new ByteArrayRange[] { new ByteArrayRange(new byte[0], new byte[0]) });
}
for (int i = 0; i < hilbertRanges.size(); i++) {
final FilteredIndexRange<BigIntegerRange, BigIntegerRange> range = hilbertRanges.get(i);
// sanity check that values fit within the expected range
// it seems that uzaygezen can produce a value at 2^totalPrecision
// rather than 2^totalPrecision - 1
final BigInteger startValue = clamp(minHilbertValue, maxHilbertValue, range.getIndexRange().getStart());
final BigInteger endValue = clamp(minHilbertValue, maxHilbertValue, range.getIndexRange().getEnd().subtract(BigInteger.ONE));
// make sure its padded if necessary
final byte[] start = HilbertSFC.fitExpectedByteCount(expectedByteCount, startValue.toByteArray());
// make sure its padded if necessary
final byte[] end = HilbertSFC.fitExpectedByteCount(expectedByteCount, endValue.toByteArray());
sfcRanges[i] = new ByteArrayRange(start, end);
}
final RangeDecomposition rangeDecomposition = new RangeDecomposition(sfcRanges);
return rangeDecomposition;
}
use of com.google.uzaygezen.core.ZoomingSpaceVisitorAdapter in project geowave by locationtech.
the class PrimitiveHilbertSFCOperations method decomposeRange.
@Override
public RangeDecomposition decomposeRange(final NumericData[] rangePerDimension, final CompactHilbertCurve compactHilbertCurve, final SFCDimensionDefinition[] dimensionDefinitions, final int totalPrecision, final int maxFilteredIndexedRanges, final boolean removeVacuum, final boolean overInclusiveOnEdge) {
// List of query range minimum
// and
// maximum
// values
final List<Long> minRangeList = new ArrayList<>();
final List<Long> maxRangeList = new ArrayList<>();
final LongContent zero = new LongContent(0L);
final List<LongRange> region = new ArrayList<>(dimensionDefinitions.length);
for (int d = 0; d < dimensionDefinitions.length; d++) {
final long normalizedMin = normalizeDimension(dimensionDefinitions[d], rangePerDimension[d].getMin(), binsPerDimension[d], true, overInclusiveOnEdge);
long normalizedMax = normalizeDimension(dimensionDefinitions[d], rangePerDimension[d].getMax(), binsPerDimension[d], false, overInclusiveOnEdge);
if (normalizedMin > normalizedMax) {
// if they're both equal, which is possible because we treat max
// as exclusive, set bin max to bin min (ie. treat it as
// inclusive in this case)
normalizedMax = normalizedMin;
}
minRangeList.add(normalizedMin);
maxRangeList.add(normalizedMax);
region.add(LongRange.of(normalizedMin, normalizedMax + 1L));
}
final long minQuadSize = getMinimumQuadSize(minRangeList, maxRangeList);
final RegionInspector<LongRange, LongContent> regionInspector = SimpleRegionInspector.create(ImmutableList.of(region), new LongContent(minQuadSize), Functions.<LongRange>identity(), LongRangeHome.INSTANCE, zero);
final PlainFilterCombiner<LongRange, Long, LongContent, LongRange> intervalCombiner = new PlainFilterCombiner<>(LongRange.of(0, 1));
final QueryBuilder<LongRange, LongRange> queryBuilder = BacktrackingQueryBuilder.create(regionInspector, intervalCombiner, maxFilteredIndexedRanges, removeVacuum, LongRangeHome.INSTANCE, zero);
synchronized (compactHilbertCurve) {
compactHilbertCurve.accept(new ZoomingSpaceVisitorAdapter(compactHilbertCurve, queryBuilder));
}
final List<FilteredIndexRange<LongRange, LongRange>> hilbertRanges = queryBuilder.get().getFilteredIndexRanges();
final ByteArrayRange[] sfcRanges = new ByteArrayRange[hilbertRanges.size()];
final int expectedByteCount = (int) Math.ceil(totalPrecision / 8.0);
if (expectedByteCount <= 0) {
// special case for no precision
return new RangeDecomposition(new ByteArrayRange[] { new ByteArrayRange(new byte[0], new byte[0]) });
}
for (int i = 0; i < hilbertRanges.size(); i++) {
final FilteredIndexRange<LongRange, LongRange> range = hilbertRanges.get(i);
// sanity check that values fit within the expected range
// it seems that uzaygezen can produce a value at 2^totalPrecision
// rather than 2^totalPrecision - 1
final long startValue = clamp(minHilbertValue, maxHilbertValue, range.getIndexRange().getStart());
final long endValue = clamp(minHilbertValue, maxHilbertValue, range.getIndexRange().getEnd() - 1);
// make sure its padded if necessary
final byte[] start = HilbertSFC.fitExpectedByteCount(expectedByteCount, ByteBuffer.allocate(8).putLong(startValue).array());
// make sure its padded if necessary
final byte[] end = HilbertSFC.fitExpectedByteCount(expectedByteCount, ByteBuffer.allocate(8).putLong(endValue).array());
sfcRanges[i] = new ByteArrayRange(start, end);
}
final RangeDecomposition rangeDecomposition = new RangeDecomposition(sfcRanges);
return rangeDecomposition;
}
use of com.google.uzaygezen.core.ZoomingSpaceVisitorAdapter in project calcite by apache.
the class HilbertCurve2D method toRanges.
@Override
public List<IndexRange> toRanges(double xMin, double yMin, double xMax, double yMax, RangeComputeHints hints) {
final CompactHilbertCurve chc = new CompactHilbertCurve(new int[] { resolution, resolution });
final List<LongRange> region = new ArrayList<>();
final long minNormalizedLongitude = getNormalizedLongitude(xMin);
final long minNormalizedLatitude = getNormalizedLatitude(yMin);
final long maxNormalizedLongitude = getNormalizedLongitude(xMax);
final long maxNormalizedLatitude = getNormalizedLatitude(yMax);
region.add(LongRange.of(minNormalizedLongitude, maxNormalizedLongitude));
region.add(LongRange.of(minNormalizedLatitude, maxNormalizedLatitude));
final LongContent zero = new LongContent(0L);
final SimpleRegionInspector<LongRange, Long, LongContent, LongRange> inspector = SimpleRegionInspector.create(ImmutableList.of(region), new LongContent(1L), range -> range, LongRangeHome.INSTANCE, zero);
final PlainFilterCombiner<LongRange, Long, LongContent, LongRange> combiner = new PlainFilterCombiner<>(LongRange.of(0, 1));
final BacktrackingQueryBuilder<LongRange, Long, LongContent, LongRange> queryBuilder = BacktrackingQueryBuilder.create(inspector, combiner, Integer.MAX_VALUE, true, LongRangeHome.INSTANCE, zero);
chc.accept(new ZoomingSpaceVisitorAdapter(chc, queryBuilder));
final Query<LongRange, LongRange> query = queryBuilder.get();
final List<FilteredIndexRange<LongRange, LongRange>> ranges = query.getFilteredIndexRanges();
// result
final List<IndexRange> result = new ArrayList<>();
for (FilteredIndexRange<LongRange, LongRange> l : ranges) {
final LongRange range = l.getIndexRange();
final Long start = range.getStart();
final Long end = range.getEnd();
final boolean contained = l.isPotentialOverSelectivity();
result.add(0, IndexRanges.create(start, end, contained));
}
return result;
}
Aggregations