mirror of https://github.com/apache/lucene.git
LUCENE-5277: Modify FixedBitSet copy constructor to take numBits to allow grow/shrink the new bitset
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1531627 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8b35981608
commit
544d997664
|
@ -146,6 +146,10 @@ API Changes:
|
||||||
* LUCENE-5275: Change AttributeSource.toString() to display the current
|
* LUCENE-5275: Change AttributeSource.toString() to display the current
|
||||||
state of attributes. (Robert Muir)
|
state of attributes. (Robert Muir)
|
||||||
|
|
||||||
|
* LUCENE-5277: Modify FixedBitSet copy constructor to take an additional
|
||||||
|
numBits parameter to allow growing/shrinking the copied bitset. You can
|
||||||
|
use FixedBitSet.clone() if you only need to clone the bitset. (Shai Erera)
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
|
|
||||||
* LUCENE-5225: The ToParentBlockJoinQuery only keeps tracks of the the child
|
* LUCENE-5225: The ToParentBlockJoinQuery only keeps tracks of the the child
|
||||||
|
|
|
@ -35,7 +35,6 @@ import org.apache.lucene.search.DocIdSetIterator;
|
||||||
*
|
*
|
||||||
* @lucene.internal
|
* @lucene.internal
|
||||||
**/
|
**/
|
||||||
|
|
||||||
public final class FixedBitSet extends DocIdSet implements Bits {
|
public final class FixedBitSet extends DocIdSet implements Bits {
|
||||||
private final long[] bits;
|
private final long[] bits;
|
||||||
private final int numBits;
|
private final int numBits;
|
||||||
|
@ -63,14 +62,18 @@ public final class FixedBitSet extends DocIdSet implements Bits {
|
||||||
}
|
}
|
||||||
this.numBits = numBits;
|
this.numBits = numBits;
|
||||||
this.bits = storedBits;
|
this.bits = storedBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Makes full copy. */
|
/**
|
||||||
public FixedBitSet(FixedBitSet other) {
|
* Makes a full copy of the bits, while allowing to expand/shrink the bitset.
|
||||||
bits = new long[other.wordLength];
|
* If {@code numBits < other.numBits}, then only the first {@code numBits}
|
||||||
System.arraycopy(other.bits, 0, bits, 0, other.wordLength);
|
* are copied from other.
|
||||||
numBits = other.numBits;
|
*/
|
||||||
wordLength = other.wordLength;
|
public FixedBitSet(FixedBitSet other, int numBits) {
|
||||||
|
wordLength = bits2words(numBits);
|
||||||
|
bits = new long[wordLength];
|
||||||
|
System.arraycopy(other.bits, 0, bits, 0, Math.min(other.wordLength, wordLength));
|
||||||
|
this.numBits = numBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -403,7 +406,7 @@ public final class FixedBitSet extends DocIdSet implements Bits {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FixedBitSet clone() {
|
public FixedBitSet clone() {
|
||||||
return new FixedBitSet(this);
|
return new FixedBitSet(this, numBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** returns true if both sets have the same bits set */
|
/** returns true if both sets have the same bits set */
|
||||||
|
|
|
@ -328,7 +328,50 @@ public class TestFixedBitSet extends BaseDocIdSetTestCase<FixedBitSet> {
|
||||||
|
|
||||||
checkNextSetBitArray(new int[0], setBits.length + random().nextInt(10));
|
checkNextSetBitArray(new int[0], setBits.length + random().nextInt(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGrow() {
|
||||||
|
FixedBitSet bits = new FixedBitSet(5);
|
||||||
|
bits.set(1);
|
||||||
|
bits.set(4);
|
||||||
|
|
||||||
|
FixedBitSet newBits = new FixedBitSet(bits, 8); // grow within the word
|
||||||
|
assertTrue(newBits.get(1));
|
||||||
|
assertTrue(newBits.get(4));
|
||||||
|
|
||||||
|
newBits = new FixedBitSet(bits, 72); // grow beyond one word
|
||||||
|
assertTrue(newBits.get(1));
|
||||||
|
assertTrue(newBits.get(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testShrink() {
|
||||||
|
FixedBitSet bits = new FixedBitSet(72);
|
||||||
|
bits.set(1);
|
||||||
|
bits.set(4);
|
||||||
|
bits.set(69);
|
||||||
|
|
||||||
|
FixedBitSet newBits = new FixedBitSet(bits, 66); // shrink within the word
|
||||||
|
assertTrue(newBits.get(1));
|
||||||
|
assertTrue(newBits.get(4));
|
||||||
|
boolean hitError = true;
|
||||||
|
try {
|
||||||
|
newBits.get(69);
|
||||||
|
hitError = false;
|
||||||
|
} catch (AssertionError e) {
|
||||||
|
hitError = true;
|
||||||
|
}
|
||||||
|
assertTrue(hitError);
|
||||||
|
|
||||||
|
newBits = new FixedBitSet(bits, 8); // shrink beyond one word
|
||||||
|
assertTrue(newBits.get(1));
|
||||||
|
assertTrue(newBits.get(4));
|
||||||
|
hitError = true;
|
||||||
|
try {
|
||||||
|
newBits.get(69);
|
||||||
|
hitError = false;
|
||||||
|
} catch (AssertionError e) {
|
||||||
|
hitError = true;
|
||||||
|
}
|
||||||
|
assertTrue(hitError);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue