Skip to content

Commit

Permalink
Replace special-casing of DocBaseBitSetIterator with #intoBitSet. (
Browse files Browse the repository at this point in the history
…#14139)

This takes advantage of the new `#intoBitSet` API to remove special casing of
`DocBaseBitSetIterator` in `FixedBitSet#or(DocIdSetIterator)`.
  • Loading branch information
jpountz committed Jan 21, 2025
1 parent 1b494c5 commit 1a3db4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.lucene.util;

import java.io.IOException;
import org.apache.lucene.search.DocIdSetIterator;

/**
Expand Down Expand Up @@ -89,4 +90,18 @@ public int advance(int target) {
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);
}
}
27 changes: 3 additions & 24 deletions lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,30 +339,9 @@ public int prevSetBit(int index) {

@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}. */
Expand Down

0 comments on commit 1a3db4c

Please sign in to comment.