Created
December 1, 2020 12:14
-
-
Save ppiotrow/8c90593e74dc1ce0bc527d30940a5564 to your computer and use it in GitHub Desktop.
NonEmptyRangesCounter (no partitions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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