allow to copy openbitset into a sliced one
This commit is contained in:
parent
991683efa6
commit
b658fba22e
|
@ -21,6 +21,7 @@ package org.elasticsearch.common.lucene.docset;
|
|||
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
import org.apache.lucene.util.BitUtil;
|
||||
import org.apache.lucene.util.OpenBitSet;
|
||||
import org.elasticsearch.common.RamUsage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -35,6 +36,13 @@ public class SlicedOpenBitSet extends DocSet {
|
|||
private final int wlen; // number of words (elements) used in the array
|
||||
private final int from; // the from index in the array
|
||||
|
||||
public SlicedOpenBitSet(long[] bits, int from, OpenBitSet setToCopy) {
|
||||
this.bits = bits;
|
||||
this.from = from;
|
||||
System.arraycopy(setToCopy.getBits(), 0, bits, from, setToCopy.getBits().length);
|
||||
this.wlen = setToCopy.getNumWords();
|
||||
}
|
||||
|
||||
public SlicedOpenBitSet(long[] bits, int wlen, int from) {
|
||||
this.bits = bits;
|
||||
this.wlen = wlen;
|
||||
|
|
|
@ -42,4 +42,13 @@ public class SlicedOpenBitSetTests {
|
|||
assertThat(iterator.nextDoc(), equalTo(100));
|
||||
assertThat(iterator.nextDoc(), equalTo(DocIdSetIterator.NO_MORE_DOCS));
|
||||
}
|
||||
|
||||
@Test public void testCopy() throws IOException {
|
||||
int numberOfBits = 500;
|
||||
OpenBitSet bitSet = new OpenBitSet(numberOfBits);
|
||||
bitSet.set(100);
|
||||
|
||||
SlicedOpenBitSet sBitSet = new SlicedOpenBitSet(new long[OpenBitSet.bits2words(numberOfBits) + 33], 33, bitSet);
|
||||
assertThat(sBitSet.get(100), equalTo(true));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue