You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2025/01/21 09:38:12 UTC

(lucene) branch main updated: Replace special-casing of `DocBaseBitSetIterator` with `#intoBitSet`. (#14139)

This is an automated email from the ASF dual-hosted git repository.

jpountz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 04eecb0483e Replace special-casing of `DocBaseBitSetIterator` with `#intoBitSet`. (#14139)
04eecb0483e is described below

commit 04eecb0483ee3be1fdaa302e27443977914a870d
Author: Adrien Grand <jp...@gmail.com>
AuthorDate: Tue Jan 21 10:38:05 2025 +0100

    Replace special-casing of `DocBaseBitSetIterator` with `#intoBitSet`. (#14139)
    
    This takes advantage of the new `#intoBitSet` API to remove special casing of
    `DocBaseBitSetIterator` in `FixedBitSet#or(DocIdSetIterator)`.
---
 .../apache/lucene/util/DocBaseBitSetIterator.java  | 15 ++++++++++++
 .../java/org/apache/lucene/util/FixedBitSet.java   | 27 +++-------------------
 2 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/lucene/core/src/java/org/apache/lucene/util/DocBaseBitSetIterator.java b/lucene/core/src/java/org/apache/lucene/util/DocBaseBitSetIterator.java
index 841149f4feb..cf9bf5432b4 100644
--- a/lucene/core/src/java/org/apache/lucene/util/DocBaseBitSetIterator.java
+++ b/lucene/core/src/java/org/apache/lucene/util/DocBaseBitSetIterator.java
@@ -16,6 +16,7 @@
  */
 package org.apache.lucene.util;
 
+import java.io.IOException;
 import org.apache.lucene.search.DocIdSetIterator;
 
 /**
@@ -89,4 +90,18 @@ public class DocBaseBitSetIterator extends DocIdSetIterator {
   public long cost() {
     return cost;
   }
+
+  @Override
+  public void intoBitSet(int upTo, FixedBitSet bitSet, int offset) throws IOException {
+    int actualUpto = Math.min(upTo, length);
+    // The destination bit set may be shorter than this bit set. This is only legal if all bits
+    // beyond offset + bitSet.length() are clear. If not, the below call to `super.intoBitSet` will
+    // throw an exception.
+    actualUpto = (int) Math.min(actualUpto, offset + (long) bitSet.length());
+    if (actualUpto > doc) {
+      FixedBitSet.orRange(bits, doc - docBase, bitSet, doc - offset, actualUpto - doc);
+      advance(actualUpto); // set the current doc
+    }
+    super.intoBitSet(upTo, bitSet, offset);
+  }
 }
diff --git a/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java b/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java
index 1b6954d2eb6..9867582dd52 100644
--- a/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java
+++ b/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java
@@ -339,30 +339,9 @@ public final class FixedBitSet extends BitSet {
 
   @Override
   public void or(DocIdSetIterator iter) throws IOException {
-    if (iter instanceof DocBaseBitSetIterator) {
-      // TODO: implement DocBaseBitSetIterator#intoBitSet instead
-      checkUnpositioned(iter);
-      DocBaseBitSetIterator baseIter = (DocBaseBitSetIterator) iter;
-      or(baseIter.getDocBase() >> 6, baseIter.getBitSet());
-    } else {
-      checkUnpositioned(iter);
-      iter.nextDoc();
-      iter.intoBitSet(DocIdSetIterator.NO_MORE_DOCS, this, 0);
-    }
-  }
-
-  private void or(final int otherOffsetWords, FixedBitSet other) {
-    or(otherOffsetWords, other.bits, other.numWords);
-  }
-
-  private void or(final int otherOffsetWords, final long[] otherArr, final int otherNumWords) {
-    assert otherNumWords + otherOffsetWords <= numWords
-        : "numWords=" + numWords + ", otherNumWords=" + otherNumWords;
-    int pos = Math.min(numWords - otherOffsetWords, otherNumWords);
-    final long[] thisArr = this.bits;
-    while (--pos >= 0) {
-      thisArr[pos + otherOffsetWords] |= otherArr[pos];
-    }
+    checkUnpositioned(iter);
+    iter.nextDoc();
+    iter.intoBitSet(DocIdSetIterator.NO_MORE_DOCS, this, 0);
   }
 
   /** Read {@code numBits} (between 1 and 63) bits from {@code bitSet} at {@code from}. */