You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by yo...@apache.org on 2007/06/22 22:27:29 UTC
svn commit: r549948 - in /lucene/solr/trunk/src:
java/org/apache/solr/util/OpenBitSet.java
test/org/apache/solr/util/TestOpenBitSet.java
Author: yonik
Date: Fri Jun 22 13:27:28 2007
New Revision: 549948
URL: http://svn.apache.org/viewvc?view=rev&rev=549948
Log:
fix OpenBitSet.flip bug when indicies outside current size
Modified:
lucene/solr/trunk/src/java/org/apache/solr/util/OpenBitSet.java
lucene/solr/trunk/src/test/org/apache/solr/util/TestOpenBitSet.java
Modified: lucene/solr/trunk/src/java/org/apache/solr/util/OpenBitSet.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/util/OpenBitSet.java?view=diff&rev=549948&r1=549947&r2=549948
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/util/OpenBitSet.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/util/OpenBitSet.java Fri Jun 22 13:27:28 2007
@@ -330,6 +330,7 @@
if (endIndex <= startIndex) return;
int startWord = (int)(startIndex>>6);
+ if (startWord >= wlen) return;
// since endIndex is one past the end, this is index of the last
// word to be changed.
@@ -439,7 +440,6 @@
*/
public void flip(long startIndex, long endIndex) {
if (endIndex <= startIndex) return;
-
int oldlen = wlen;
int startWord = (int)(startIndex>>6);
@@ -455,7 +455,7 @@
***/
long startmask = -1L << startIndex;
- long endmask = -1L >>> -endIndex; // 64-endIndex is the same as -endIndex due to wrap
+ long endmask = -1L >>> -endIndex; // 64-(endIndex&0x3f) is the same as -endIndex due to wrap
if (startWord == endWord) {
bits[startWord] ^= (startmask & endmask);
@@ -464,13 +464,8 @@
bits[startWord] ^= startmask;
- int middle = Math.min(oldlen, endWord);
- for (int i=startWord+1; i<middle; i++) {
+ for (int i=startWord+1; i<endWord; i++) {
bits[i] = ~bits[i];
- }
-
- if (endWord>middle) {
- Arrays.fill(bits,middle,endWord,-1L);
}
bits[endWord] ^= endmask;
Modified: lucene/solr/trunk/src/test/org/apache/solr/util/TestOpenBitSet.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/util/TestOpenBitSet.java?view=diff&rev=549948&r1=549947&r2=549948
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/util/TestOpenBitSet.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/util/TestOpenBitSet.java Fri Jun 22 13:27:28 2007
@@ -76,26 +76,6 @@
int nOper = rand.nextInt(sz);
for (int j=0; j<nOper; j++) {
int idx;
- int idx1,idx2;
-
- idx1 = rand.nextInt(sz);
- idx2 = rand.nextInt(sz);
- if (idx1>idx2) { idx=idx1; idx1=idx2; idx2=idx; }
- a.set(idx1,idx2);
- b.set(idx1,idx2);
-
- idx1 = rand.nextInt(sz);
- idx2 = rand.nextInt(sz);
- if (idx1>idx2) { idx=idx1; idx1=idx2; idx2=idx; }
- a.clear(idx1,idx2);
- b.clear(idx1,idx2);
-
- idx1 = rand.nextInt(sz);
- idx2 = rand.nextInt(sz);
- if (idx1>idx2) { idx=idx1; idx1=idx2; idx2=idx; }
- a.flip(idx1,idx2);
- b.flip(idx1,idx2);
-
idx = rand.nextInt(sz);
a.set(idx);
@@ -122,15 +102,30 @@
// test that the various ways of accessing the bits are equivalent
doGet(a,b);
- doNextSetBit(a,b);
- doIterate(a,b);
- // test negation
- int fromIndex = rand.nextInt(sz+80);
- int toIndex = fromIndex + rand.nextInt((sz>>1)+1);
- BitSet a_not = (BitSet)a.clone(); a_not.flip(fromIndex,toIndex);
- OpenBitSet b_not = (OpenBitSet)b.clone(); b_not.flip(fromIndex,toIndex);
- doIterate(a,b);
+ // test ranges, including possible extension
+ int fromIndex, toIndex;
+ fromIndex = rand.nextInt(sz+80);
+ toIndex = fromIndex + rand.nextInt((sz>>1)+1);
+ BitSet aa = (BitSet)a.clone(); aa.flip(fromIndex,toIndex);
+ OpenBitSet bb = (OpenBitSet)b.clone(); bb.flip(fromIndex,toIndex);
+
+ doIterate(aa,bb); // a problem here is from flip or doIterate
+
+ fromIndex = rand.nextInt(sz+80);
+ toIndex = fromIndex + rand.nextInt((sz>>1)+1);
+ aa = (BitSet)a.clone(); aa.clear(fromIndex,toIndex);
+ bb = (OpenBitSet)b.clone(); bb.clear(fromIndex,toIndex);
+
+ doNextSetBit(aa,bb); // a problem here is from clear() or nextSetBit
+
+ fromIndex = rand.nextInt(sz+80);
+ toIndex = fromIndex + rand.nextInt((sz>>1)+1);
+ aa = (BitSet)a.clone(); aa.set(fromIndex,toIndex);
+ bb = (OpenBitSet)b.clone(); bb.set(fromIndex,toIndex);
+
+ doNextSetBit(aa,bb); // a problem here is from set() or nextSetBit
+
if (a0 != null) {
assertEquals( a.equals(a0), b.equals(b0));