epotyom commented on code in PR #13559: URL: https://github.com/apache/lucene/pull/13559#discussion_r1697615867
########## lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java: ########## @@ -291,6 +291,32 @@ public int nextSetBit(int index) { return DocIdSetIterator.NO_MORE_DOCS; } + @Override + public int firstSetBitInRange(int start, int upperBound) { + // Depends on the ghost bits being clear! + assert start >= 0 && start < numBits : "index=" + start + ", numBits=" + numBits; + assert start <= upperBound : "index=" + start + ", upperBound=" + upperBound; + int i = start >> 6; + long word = bits[i] >> start; // skip all the bits to the right of index + + if (word != 0) { + int res = start + Long.numberOfTrailingZeros(word); + return res > upperBound ? DocIdSetIterator.NO_MORE_DOCS : res; + } + + int maxWord = Math.min((upperBound >> 6) + 1, numWords); Review Comment: I've ended up removing `Math.min` here and making `upperBound <= bit set size` a requirement for the method - there is similar requirement for `index` parameter. Will push a commit shortly - please let me know what you think. ########## lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java: ########## @@ -353,14 +355,47 @@ public int nextSetBit(int i) { final long indexBits = index >>> i64 >>> 1; if (indexBits == 0) { // no more bits are set in the current block of 4096 bits, go to the next one - return firstDoc(i4096 + 1); + return firstDoc(i4096 + 1, indices.length); } // there are still set bits i64 += 1 + Long.numberOfTrailingZeros(indexBits); final long bits = bitArray[o]; return (i64 << 6) | Long.numberOfTrailingZeros(bits); } + @Override + public int firstSetBitInRange(int start, int upperBound) { + assert start < length; + assert upperBound >= start; + final int i4096 = start >>> 12; + final long index = indices[i4096]; + final long[] bitArray = this.bits[i4096]; + int i64 = start >>> 6; + int o = Long.bitCount(index & ((1L << i64) - 1)); Review Comment: Make sense! -- 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. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org