Java Code Examples for org.roaringbitmap.RoaringBitmap#andNot()

The following examples show how to use org.roaringbitmap.RoaringBitmap#andNot() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InvertedIndexTagStore.java    From yuvi with Apache License 2.0 5 votes vote down vote up
/**
 * This function fetches the ids in tag store that match the given query. In the current OpenTSDB
 * use case, a typical query consists of a metric name and a set of tag matchers. Currently, we
 * can have only one tagMatcher per tag key and a tag matcher is not reused, so we inline the tag
 * key and value parsing logic here. If tag matchers in slow path are used among queries, it is
 * worth creating a specialized tag matcher class for each match type.
 */
private RoaringBitmap lookupIds(final Query q) {
  Predicate<TagMatcher> notTagMatcher =
      t -> (t.type == MatchType.NOT_LITERAL_OR || t.type == MatchType.NOT_ILITERAL_OR);

  List<TagMatcher> inclusiveTagMatchers =
      q.tagMatchers.stream().filter(notTagMatcher.negate()).collect(Collectors.toList());

  List<TagMatcher> exclusionTagMatchers =
      q.tagMatchers.stream().filter(notTagMatcher).collect(Collectors.toList());

  // If no tag filters are specifed, then just match on metric name. If no exclusion tag filters
  // are given just match on the included tag filters.
  if ((inclusiveTagMatchers.isEmpty() && exclusionTagMatchers.isEmpty())
      || (!inclusiveTagMatchers.isEmpty() && exclusionTagMatchers.isEmpty())) {

    return getIncludedIds(q.metricName, inclusiveTagMatchers);
  }

  // If only exclusion tag matchers are specified, get all the metrics that match the wildcard
  // tag and then remove the omit the ones that match the OR query.
  // TODO: This case can be slightly faster if there is a function that computes negations.
  if (inclusiveTagMatchers.isEmpty() && !exclusionTagMatchers.isEmpty()) {
    inclusiveTagMatchers = exclusionTagMatchers.stream()
        .map(matcher -> TagMatcher.wildcardMatch(matcher.tag.key, "*"))
        .collect(Collectors.toList());
  }

  // If both included and excluded tag matchers are given, do a difference operation.
  RoaringBitmap inclusiveIds = getIncludedIds(q.metricName, inclusiveTagMatchers);
  RoaringBitmap excludedIds = getExcludedIds(q.metricName, exclusionTagMatchers);
  return RoaringBitmap.andNot(inclusiveIds, excludedIds);
}
 
Example 2
Source File: RoaringBitmapBenchmark.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public RoaringBitmap inplace_andNot() {
  RoaringBitmap b1 = bitmap1.clone();
  b1.andNot(bitmap2);
  return b1;
}
 
Example 3
Source File: RoaringBitmapBenchmark.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public RoaringBitmap inplace_andNot() {
  RoaringBitmap b1 = bitmap1.clone();
  b1.andNot(bitmap2);
  return b1;
}
 
Example 4
Source File: RoaringBitmapBenchmark.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public RoaringBitmap inplace_andNot() {
  RoaringBitmap b1 = bitmap1.clone();
  b1.andNot(bitmap2);
  return b1;
}
 
Example 5
Source File: ArrayContainerAndNotRunContainerBenchmark.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
@Benchmark
public RoaringBitmap pairwiseACAndNotRC(RealDataRoaringOnlyBenchmarkState bs) {
  RoaringBitmap last = null;
  for (int k = 0; k + 1 < bs.bitmaps.size(); ++k) {
    last = RoaringBitmap.andNot(bs.onlyArrayContainers.get(k), bs.onlyRunContainers.get(k + 1));
  }
  return last;
}
 
Example 6
Source File: RoaringBitmapBenchmark.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public RoaringBitmap andNot() {
  return RoaringBitmap.andNot(bitmap1, bitmap2);
}
 
Example 7
Source File: RoaringBitmapBenchmark.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public RoaringBitmap andNot() {
  return RoaringBitmap.andNot(bitmap1, bitmap2);
}
 
Example 8
Source File: RoaringBitmapBenchmark.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public RoaringBitmap andNot() {
  return RoaringBitmap.andNot(bitmap1, bitmap2);
}
 
Example 9
Source File: RoaringBitmapWrapper.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
@Override
public Bitmap andNot(Bitmap other) {
  return new RoaringBitmapWrapper(
      RoaringBitmap.andNot(bitmap, ((RoaringBitmapWrapper) other).bitmap));
}