Skip to content

Commit c64ee66

Browse files
committed
LUCENE-10311: add long method, that forwards to int method and truncates
Confusion happens because grow(numAdds) reserves space for you to call add() up to numAdds times. When numAdds exceeds a "threshold" (maxdoc >> 8), we really don't care about big numbers at all: we'll switch to a FixedBitSet(maxDoc) with fixed sized storage, bounded only by maxDoc. But we can just add a one-liner grow(long) that doesn't require the caller to understand any of this, and hide it via implementation detail.
1 parent ce172ec commit c64ee66

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lucene/core/src/java/org/apache/lucene/util/DocIdSetBuilder.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,23 @@ public void add(DocIdSetIterator iter) throws IOException {
144144
}
145145

146146
/**
147-
* Reserve space and return a {@link BulkAdder} object that can be used to add up to {@code
148-
* numDocs} documents.
147+
* Reserve space and return a {@link BulkAdder} object that supports up to {@code numAdds}
148+
* invocations of {@link BulkAdder#add(int)}.
149149
*/
150-
public BulkAdder grow(int numDocs) {
150+
public BulkAdder grow(long numAdds) {
151+
// as an impl detail, we don't need to care about numbers bigger than int32,
152+
// we switch over to FixedBitSet storage well before that threshold.
153+
return grow((int) Math.min(Integer.MAX_VALUE, numAdds));
154+
}
155+
156+
/**
157+
* Reserve space and return a {@link BulkAdder} object that supports up to {@code numAdds}
158+
* invocations of {@link BulkAdder#add(int)}.
159+
*/
160+
public BulkAdder grow(int numAdds) {
151161
if (bitSet == null) {
152-
if ((long) totalAllocated + numDocs <= threshold) {
153-
ensureBufferCapacity(numDocs);
162+
if ((long) totalAllocated + numAdds <= threshold) {
163+
ensureBufferCapacity(numAdds);
154164
} else {
155165
upgradeToBitSet();
156166
}

0 commit comments

Comments
 (0)