Skip to content

Instantly share code, notes, and snippets.

@ppiotrow
Created December 1, 2020 12:14
Show Gist options
  • Save ppiotrow/8c90593e74dc1ce0bc527d30940a5564 to your computer and use it in GitHub Desktop.
Save ppiotrow/8c90593e74dc1ce0bc527d30940a5564 to your computer and use it in GitHub Desktop.
NonEmptyRangesCounter (no partitions)
private[evaluator] object NonEmptyRangesCounter {
def count(source: ImmutableRoaringBitmap, ranges: ImmutableRoaringBitmap): Int = {
val rangesIter = ranges.getIntIterator
val sourceIter = source.getIntIterator
var distinct = 0
var continue = rangesIter.hasNext
while (continue) {
val rangeStart = rangesIter.next()
sourceIter.advanceIfNeeded(rangeStart)
if (sourceIter.hasNext) {
val el = sourceIter.next()
distinct += (if (el >= rangeStart) 1 else 0)
rangesIter.advanceIfNeeded(el + 1)
continue = rangesIter.hasNext
} else {
continue = false
}
}
distinct
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment