mirror of https://github.com/apache/lucene.git
LUCENE-3179: Fix bug in handling of indexes >= size in OpenBitSet.prevSetBit()
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1139431 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a23091d9df
commit
7574f33abe
|
@ -664,15 +664,19 @@ public class OpenBitSet extends DocIdSet implements Bits, Cloneable {
|
|||
* -1 is returned if there are no more set bits.
|
||||
*/
|
||||
public int prevSetBit(int index) {
|
||||
if (index < 0) {
|
||||
return -1;
|
||||
}
|
||||
int i = index>>6;
|
||||
int i = index >> 6;
|
||||
final int subIndex;
|
||||
long word;
|
||||
if (i >= wlen) {
|
||||
i = wlen - 1;
|
||||
if (i < 0) return -1;
|
||||
subIndex = 63; // last possible bit
|
||||
word = bits[i];
|
||||
} else {
|
||||
if (i < 0) return -1;
|
||||
subIndex = index & 0x3f; // index within the word
|
||||
word = (bits[i] << (63-subIndex)); // skip all the bits to the left of index
|
||||
}
|
||||
final int subIndex = index & 0x3f; // index within the word
|
||||
long word = (bits[i] << (63-subIndex)); // skip all the bits to the left of index
|
||||
|
||||
if (word != 0) {
|
||||
return (i << 6) + subIndex - Long.numberOfLeadingZeros(word); // See LUCENE-3197
|
||||
|
|
|
@ -42,8 +42,8 @@ public class TestOpenBitSet extends LuceneTestCase {
|
|||
}
|
||||
|
||||
void doPrevSetBit(BitSet a, OpenBitSet b) {
|
||||
int aa=a.length();
|
||||
int bb=aa;
|
||||
int aa = a.size() + random.nextInt(100);
|
||||
int bb = aa;
|
||||
do {
|
||||
// aa = a.prevSetBit(aa-1);
|
||||
aa--;
|
||||
|
|
Loading…
Reference in New Issue