Search in sources :

Example 1 with LongRange

use of com.google.uzaygezen.core.ranges.LongRange 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;
}
Also used : FilteredIndexRange(com.google.uzaygezen.core.FilteredIndexRange) ArrayList(java.util.ArrayList) ZoomingSpaceVisitorAdapter(com.google.uzaygezen.core.ZoomingSpaceVisitorAdapter) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange) LongContent(com.google.uzaygezen.core.LongContent) PlainFilterCombiner(com.google.uzaygezen.core.PlainFilterCombiner) LongRange(com.google.uzaygezen.core.ranges.LongRange) RangeDecomposition(org.locationtech.geowave.core.index.sfc.RangeDecomposition)

Example 2 with LongRange

use of com.google.uzaygezen.core.ranges.LongRange 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;
}
Also used : FilteredIndexRange(com.google.uzaygezen.core.FilteredIndexRange) ArrayList(java.util.ArrayList) ZoomingSpaceVisitorAdapter(com.google.uzaygezen.core.ZoomingSpaceVisitorAdapter) CompactHilbertCurve(com.google.uzaygezen.core.CompactHilbertCurve) LongContent(com.google.uzaygezen.core.LongContent) PlainFilterCombiner(com.google.uzaygezen.core.PlainFilterCombiner) FilteredIndexRange(com.google.uzaygezen.core.FilteredIndexRange) LongRange(com.google.uzaygezen.core.ranges.LongRange)

Aggregations

FilteredIndexRange (com.google.uzaygezen.core.FilteredIndexRange)2 LongContent (com.google.uzaygezen.core.LongContent)2 PlainFilterCombiner (com.google.uzaygezen.core.PlainFilterCombiner)2 ZoomingSpaceVisitorAdapter (com.google.uzaygezen.core.ZoomingSpaceVisitorAdapter)2 LongRange (com.google.uzaygezen.core.ranges.LongRange)2 ArrayList (java.util.ArrayList)2 CompactHilbertCurve (com.google.uzaygezen.core.CompactHilbertCurve)1 ByteArrayRange (org.locationtech.geowave.core.index.ByteArrayRange)1 RangeDecomposition (org.locationtech.geowave.core.index.sfc.RangeDecomposition)1