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:
Uwe Schindler 2011-06-24 20:43:46 +00:00
parent a23091d9df
commit 7574f33abe
2 changed files with 12 additions and 8 deletions

View File

@ -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;
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

View File

@ -42,7 +42,7 @@ public class TestOpenBitSet extends LuceneTestCase {
}
void doPrevSetBit(BitSet a, OpenBitSet b) {
int aa=a.length();
int aa = a.size() + random.nextInt(100);
int bb = aa;
do {
// aa = a.prevSetBit(aa-1);