jpountz commented on a change in pull request #667: LUCENE-8796: Use 
exponential search in IntArrayDocIdSetIterator#advance
URL: https://github.com/apache/lucene-solr/pull/667#discussion_r290223745
 
 

 ##########
 File path: lucene/core/src/java/org/apache/lucene/util/IntArrayDocIdSet.java
 ##########
 @@ -67,16 +67,21 @@ public int docID() {
 
     @Override
     public int nextDoc() throws IOException {
-      return doc = docs[++i];
+      return doc = docs[i++];
     }
 
     @Override
     public int advance(int target) throws IOException {
-      i = Arrays.binarySearch(docs, i + 1, length, target);
+      int bound = 1;
+      //given that we use this for small arrays only, this is very unlikely to 
overflow
+      while(i + bound < length && docs[i + bound] < target) {
+        bound *= 2;
+      }
+      i = Arrays.binarySearch(docs, i + bound / 2, Math.min(i + bound, 
length), target);
 
 Review comment:
   I think it should be `binarySearch(docs, i + bound / 2, Math.min(i + bound + 
1, length), target);`? (maybe we need a test for this special case that the 
result is found at `i + bound` exactly?)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to