com.facebook.presto.spi.predicate.Range.overlaps()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中com.facebook.presto.spi.predicate.Range.overlaps方法的一些代码示例,展示了Range.overlaps的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Range.overlaps方法的具体详情如下:
包路径:com.facebook.presto.spi.predicate.Range
类名称:Range
方法名:overlaps

Range.overlaps介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

SortedRangeSet build()
  {
    Collections.sort(ranges, Comparator.comparing(Range::getLow));
    NavigableMap<Marker, Range> result = new TreeMap<>();
    Range current = null;
    for (Range next : ranges) {
      if (current == null) {
        current = next;
        continue;
      }
      if (current.overlaps(next) || current.getHigh().isAdjacent(next.getLow())) {
        current = current.span(next);
      }
      else {
        result.put(current.getLow(), current);
        current = next;
      }
    }
    if (current != null) {
      result.put(current.getLow(), current);
    }
    return new SortedRangeSet(type, result);
  }
}

代码示例来源:origin: prestodb/presto

@Override
public SortedRangeSet intersect(ValueSet other)
{
  SortedRangeSet otherRangeSet = checkCompatibility(other);
  Builder builder = new Builder(type);
  Iterator<Range> iterator1 = getOrderedRanges().iterator();
  Iterator<Range> iterator2 = otherRangeSet.getOrderedRanges().iterator();
  if (iterator1.hasNext() && iterator2.hasNext()) {
    Range range1 = iterator1.next();
    Range range2 = iterator2.next();
    while (true) {
      if (range1.overlaps(range2)) {
        builder.add(range1.intersect(range2));
      }
      if (range1.getHigh().compareTo(range2.getHigh()) <= 0) {
        if (!iterator1.hasNext()) {
          break;
        }
        range1 = iterator1.next();
      }
      else {
        if (!iterator2.hasNext()) {
          break;
        }
        range2 = iterator2.next();
      }
    }
  }
  return builder.build();
}

代码示例来源:origin: prestodb/presto

public Range intersect(Range other)
{
  checkTypeCompatibility(other);
  if (!this.overlaps(other)) {
    throw new IllegalArgumentException("Cannot intersect non-overlapping ranges");
  }
  Marker lowMarker = Marker.max(low, other.getLow());
  Marker highMarker = Marker.min(high, other.getHigh());
  return new Range(lowMarker, highMarker);
}

代码示例来源:origin: prestodb/presto

@Test
public void testOverlaps()
{
  assertTrue(Range.greaterThan(BIGINT, 1L).overlaps(Range.lessThanOrEqual(BIGINT, 2L)));
  assertFalse(Range.greaterThan(BIGINT, 2L).overlaps(Range.lessThan(BIGINT, 2L)));
  assertTrue(Range.range(BIGINT, 1L, true, 3L, false).overlaps(Range.equal(BIGINT, 2L)));
  assertTrue(Range.range(BIGINT, 1L, true, 3L, false).overlaps(Range.range(BIGINT, 2L, false, 10L, false)));
  assertFalse(Range.range(BIGINT, 1L, true, 3L, false).overlaps(Range.range(BIGINT, 3L, true, 10L, false)));
  assertTrue(Range.range(BIGINT, 1L, true, 3L, true).overlaps(Range.range(BIGINT, 3L, true, 10L, false)));
  assertTrue(Range.all(BIGINT).overlaps(Range.equal(BIGINT, Long.MAX_VALUE)));
}

代码示例来源:origin: com.facebook.presto/presto-spi

@Override
public SortedRangeSet intersect(ValueSet other)
{
  SortedRangeSet otherRangeSet = checkCompatibility(other);
  Builder builder = new Builder(type);
  Iterator<Range> iterator1 = getOrderedRanges().iterator();
  Iterator<Range> iterator2 = otherRangeSet.getOrderedRanges().iterator();
  if (iterator1.hasNext() && iterator2.hasNext()) {
    Range range1 = iterator1.next();
    Range range2 = iterator2.next();
    while (true) {
      if (range1.overlaps(range2)) {
        builder.add(range1.intersect(range2));
      }
      if (range1.getHigh().compareTo(range2.getHigh()) <= 0) {
        if (!iterator1.hasNext()) {
          break;
        }
        range1 = iterator1.next();
      }
      else {
        if (!iterator2.hasNext()) {
          break;
        }
        range2 = iterator2.next();
      }
    }
  }
  return builder.build();
}

代码示例来源:origin: com.facebook.presto/presto-spi

SortedRangeSet build()
  {
    Collections.sort(ranges, Comparator.comparing(Range::getLow));
    NavigableMap<Marker, Range> result = new TreeMap<>();
    Range current = null;
    for (Range next : ranges) {
      if (current == null) {
        current = next;
        continue;
      }
      if (current.overlaps(next) || current.getHigh().isAdjacent(next.getLow())) {
        current = current.span(next);
      }
      else {
        result.put(current.getLow(), current);
        current = next;
      }
    }
    if (current != null) {
      result.put(current.getLow(), current);
    }
    return new SortedRangeSet(type, result);
  }
}

代码示例来源:origin: com.facebook.presto/presto-spi

public Range intersect(Range other)
{
  checkTypeCompatibility(other);
  if (!this.overlaps(other)) {
    throw new IllegalArgumentException("Cannot intersect non-overlapping ranges");
  }
  Marker lowMarker = Marker.max(low, other.getLow());
  Marker highMarker = Marker.min(high, other.getHigh());
  return new Range(lowMarker, highMarker);
}

相关文章