Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ Optimizations

* GITHUB#14980: Add bulk off-heap scoring for float32 vectors (Chris Hegarty)

* GITHUB#15045: Use FixedBitSet#cardinality for counting liveDocs in CheckIndex (Zhang Chao)

Changes in Runtime Behavior
---------------------
* GITHUB#14823: Decrease TieredMergePolicy's default number of segments per
Expand Down
7 changes: 1 addition & 6 deletions lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -1297,12 +1297,7 @@ public static Status.LiveDocStatus testLiveDocs(
if (liveDocs == null) {
throw new CheckIndexException("segment should have deletions, but liveDocs is null");
} else {
int numLive = 0;
for (int j = 0; j < liveDocs.length(); j++) {
if (liveDocs.get(j)) {
numLive++;
}
}
int numLive = FixedBitSet.cardinality(liveDocs, 0, liveDocs.length());
if (numLive != numDocs) {
throw new CheckIndexException(
"liveDocs count mismatch: info=" + numDocs + ", vs bits=" + numLive);
Expand Down
13 changes: 2 additions & 11 deletions lucene/core/src/java/org/apache/lucene/index/PendingDeletes.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,7 @@ void onNewReader(CodecReader reader, SegmentCommitInfo info) throws IOException

private boolean assertCheckLiveDocs(Bits bits, int expectedLength, int expectedDeleteCount) {
assert bits.length() == expectedLength;
int deletedCount = 0;
for (int i = 0; i < bits.length(); i++) {
if (bits.get(i) == false) {
deletedCount++;
}
}
int deletedCount = bits.length() - FixedBitSet.cardinality(bits, 0, bits.length());
assert deletedCount == expectedDeleteCount
: "deleted: " + deletedCount + " != expected: " + expectedDeleteCount;
return true;
Expand Down Expand Up @@ -255,11 +250,7 @@ boolean verifyDocCounts(CodecReader reader) {
int count = 0;
Bits liveDocs = getLiveDocs();
if (liveDocs != null) {
for (int docID = 0; docID < info.info.maxDoc(); docID++) {
if (liveDocs.get(docID)) {
count++;
}
}
count = FixedBitSet.cardinality(liveDocs, 0, info.info.maxDoc());
} else {
count = info.info.maxDoc();
}
Expand Down
15 changes: 15 additions & 0 deletions lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ public int cardinality(int from, int to) {
return cardinality;
}

/** Just like {@link #cardinality(int, int)}, return the number of set bits for {@code Bits}. */
public static int cardinality(Bits bits, int from, int to) {
assert bits != null;
if (bits instanceof FixedBits fixedBits) {
return fixedBits.bitSet.cardinality(from, to);
}
int count = 0;
for (int i = from; i < to; i++) {
if (bits.get(i)) {
count++;
}
}
return count;
}

@Override
public int approximateCardinality() {
// Naive sampling: compute the number of bits that are set on the first 16 longs every 1024
Expand Down
Loading