gszadovszky commented on code in PR #1328:
URL: https://github.com/apache/parquet-java/pull/1328#discussion_r1624573384
##########
parquet-column/src/main/java/org/apache/parquet/internal/column/columnindex/IndexIterator.java:
##########
@@ -55,6 +55,111 @@ static PrimitiveIterator.OfInt rangeTranslate(int from, int
to, IntUnaryOperator
return new IndexIterator(from, to + 1, i -> true, translator);
}
+ static PrimitiveIterator.OfInt intersection(PrimitiveIterator.OfInt lhs,
PrimitiveIterator.OfInt rhs) {
+ return new PrimitiveIterator.OfInt() {
+ private int next = fetchNext();
+
+ @Override
+ public int nextInt() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+ int result = next;
+ next = fetchNext();
+ return result;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return next != -1;
+ }
+
+ private int fetchNext() {
+ if (!lhs.hasNext() || !rhs.hasNext()) {
+ return -1;
+ }
+
+ // Since we know both iterators are in sorted order, we can iterate
linearly through until
+ // we find the next value that belongs to both iterators, or terminate
if none exist
+ int nextL = lhs.next();
+ int nextR = rhs.next();
+ while (nextL < nextR && lhs.hasNext()) {
+ nextL = lhs.next();
+ }
+ if (nextL == nextR) {
+ return nextL;
+ }
+ while (nextR < nextL && rhs.hasNext()) {
+ nextR = rhs.next();
+ }
+ if (nextL == nextR) {
+ return nextL;
+ }
Review Comment:
It seems that an outer loop is missing that would run till the end of the
shorter iterator. Example:
```
lhs: 1, 3, 5, 7
rhs: 2, 4, 6, 7
```
After these lines at the first invocation of the method `nextL` will be `3`
and `nextR` will be `4` and `-1` is about the be returned while `7` is a common
element in both.
(It also means that the unit test for this one is not complete...)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]