clairemcginty commented on code in PR #1328:
URL: https://github.com/apache/parquet-java/pull/1328#discussion_r1624642780


##########
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:
   ah I see what you mean and replicated this in a test! I think I need to use 
a broader while loop. Refactoring now.



-- 
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]

Reply via email to