public final class FixedBitSet extends BitSet implements Bits, Accountable
getBits()
)
long[], accessed with an int index, implementing Bits
and
DocIdSet
. If you need to manage more than 2.1B bits, use
LongBitSet
.Bits.MatchAllBits, Bits.MatchNoBits
Modifier and Type | Field and Description |
---|---|
private static long |
BASE_RAM_BYTES_USED |
private long[] |
bits |
private int |
numBits |
private int |
numWords |
EMPTY_ARRAY
Constructor and Description |
---|
FixedBitSet(int numBits)
Creates a new LongBitSet.
|
FixedBitSet(long[] storedBits,
int numBits)
Creates a new LongBitSet using the provided long[] array as backing store.
|
Modifier and Type | Method and Description |
---|---|
void |
and(FixedBitSet other)
this = this AND other
|
private void |
and(long[] otherArr,
int otherNumWords) |
void |
andNot(FixedBitSet other)
this = this AND NOT other
|
private void |
andNot(long[] otherArr,
int otherNumWords) |
static long |
andNotCount(FixedBitSet a,
FixedBitSet b)
Returns the popcount or cardinality of "a and not b" or
"intersection(a, not(b))".
|
Bits |
asReadOnlyBits()
Convert this instance to read-only
Bits . |
static int |
bits2words(int numBits)
returns the number of 64 bit words it would take to hold numBits
|
int |
cardinality()
Returns number of set bits.
|
void |
clear(int index)
Clear the bit at
i . |
void |
clear(int startIndex,
int endIndex)
Clears a range of bits.
|
FixedBitSet |
clone() |
static FixedBitSet |
copyOf(Bits bits)
Make a copy of the given bits.
|
static FixedBitSet |
ensureCapacity(FixedBitSet bits,
int numBits)
If the given
FixedBitSet is large enough to hold numBits+1 ,
returns the given bits, otherwise returns a new FixedBitSet which
can hold the requested number of bits. |
boolean |
equals(java.lang.Object o) |
void |
flip(int index)
Flip the bit at the provided index.
|
void |
flip(int startIndex,
int endIndex)
Flips a range of bits
|
boolean |
get(int index)
Returns the value of the bit with the specified
index . |
boolean |
getAndClear(int index) |
boolean |
getAndSet(int index) |
long[] |
getBits()
Expert.
|
int |
hashCode() |
static long |
intersectionCount(FixedBitSet a,
FixedBitSet b)
Returns the popcount or cardinality of the intersection of the two sets.
|
boolean |
intersects(FixedBitSet other)
returns true if the sets have any elements in common
|
int |
length()
Returns the number of bits in this set
|
int |
nextSetBit(int index)
Returns the index of the first set bit starting at the index specified.
|
void |
or(DocIdSetIterator iter)
Does in-place OR of the bits provided by the iterator.
|
void |
or(FixedBitSet other)
this = this OR other
|
private void |
or(long[] otherArr,
int otherNumWords) |
int |
prevSetBit(int index)
Returns the index of the last set bit before or on the index specified.
|
long |
ramBytesUsed()
Return the memory usage of this object in bytes.
|
boolean |
scanIsEmpty()
Scans the backing store to check if all bits are clear.
|
void |
set(int index)
Set the bit at
i . |
void |
set(int startIndex,
int endIndex)
Sets a range of bits
|
static long |
unionCount(FixedBitSet a,
FixedBitSet b)
Returns the popcount or cardinality of the union of the two sets.
|
private boolean |
verifyGhostBitsClear()
Checks if the bits past numBits are clear.
|
void |
xor(DocIdSetIterator iter)
Does in-place XOR of the bits provided by the iterator.
|
void |
xor(FixedBitSet other)
this = this XOR other
|
private void |
xor(long[] otherBits,
int otherNumWords) |
approximateCardinality, checkUnpositioned, of
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getChildResources
private static final long BASE_RAM_BYTES_USED
private final long[] bits
private final int numBits
private final int numWords
public FixedBitSet(int numBits)
numBits
- the number of bits neededpublic FixedBitSet(long[] storedBits, int numBits)
storedBits
- the array to use as backing storenumBits
- the number of bits actually neededpublic static FixedBitSet ensureCapacity(FixedBitSet bits, int numBits)
FixedBitSet
is large enough to hold numBits+1
,
returns the given bits, otherwise returns a new FixedBitSet
which
can hold the requested number of bits.
NOTE: the returned bitset reuses the underlying long[]
of
the given bits
if possible. Also, calling length()
on the
returned bits may return a value greater than numBits
.
public static int bits2words(int numBits)
public static long intersectionCount(FixedBitSet a, FixedBitSet b)
public static long unionCount(FixedBitSet a, FixedBitSet b)
public static long andNotCount(FixedBitSet a, FixedBitSet b)
private boolean verifyGhostBitsClear()
public int length()
Bits
public long ramBytesUsed()
Accountable
ramBytesUsed
in interface Accountable
public long[] getBits()
public int cardinality()
cardinality
in class BitSet
public boolean get(int index)
Bits
index
.get
in interface Bits
index
- index, should be non-negative and < Bits.length()
.
The result of passing negative or out of bounds values is undefined
by this interface, just don't do it!true
if the bit is set, false
otherwise.public void set(int index)
BitSet
i
.public boolean getAndSet(int index)
public void clear(int index)
BitSet
i
.public boolean getAndClear(int index)
public int nextSetBit(int index)
BitSet
DocIdSetIterator.NO_MORE_DOCS
is returned if there are no more set bits.nextSetBit
in class BitSet
public int prevSetBit(int index)
BitSet
prevSetBit
in class BitSet
public void or(DocIdSetIterator iter) throws java.io.IOException
BitSet
public void or(FixedBitSet other)
private void or(long[] otherArr, int otherNumWords)
public void xor(FixedBitSet other)
public void xor(DocIdSetIterator iter) throws java.io.IOException
java.io.IOException
private void xor(long[] otherBits, int otherNumWords)
public boolean intersects(FixedBitSet other)
public void and(FixedBitSet other)
private void and(long[] otherArr, int otherNumWords)
public void andNot(FixedBitSet other)
private void andNot(long[] otherArr, int otherNumWords)
public boolean scanIsEmpty()
public void flip(int startIndex, int endIndex)
startIndex
- lower indexendIndex
- one-past the last bit to flippublic void flip(int index)
public void set(int startIndex, int endIndex)
startIndex
- lower indexendIndex
- one-past the last bit to setpublic void clear(int startIndex, int endIndex)
BitSet
public FixedBitSet clone()
clone
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public static FixedBitSet copyOf(Bits bits)
public Bits asReadOnlyBits()
Bits
.
This is useful in the case that this FixedBitSet
is returned as a
Bits
instance, to make sure that consumers may not get write access
back by casting to a FixedBitSet
.
NOTE: Changes to this FixedBitSet
will be reflected on the returned
Bits
.