public class BitVector
Performance optimized bitset implementation. Certain operations are
prefixed with unsafe; these methods perform no validation.
| Constructor and Description |
|---|
BitVector() |
BitVector(BitVector copyFrom)
Creates a bit set based off another bit vector.
|
| Modifier and Type | Method and Description |
|---|---|
void |
and(BitVector other)
Performs a logical AND of this target bit set with the
argument bit set. This bit set is modified so that each bit in
it has the value true if and only if it both initially had the
value true and the corresponding bit in the bit set argument
also had the value true.
|
void |
andNot(BitVector other)
Clears all of the bits in this bit set whose corresponding
bit is set in the specified bit set.
|
int |
cardinality()
Returns the count of
true bits |
void |
clear(int index) |
void |
clear()
Clears the entire bitset
|
boolean |
contains(BitVector other)
Returns true if this bit set is a super set of the specified set,
i.e. it has all bits set to true that are also set to true
in the specified BitVector.
|
BitVector |
copy() |
void |
ensureCapacity(int bits)
Grows the backing array so that it can hold the requested
bits. Mostly applicable when relying on the
unsafe methods,
including BitVector.unsafeGet and BitVector.unsafeClear. |
boolean |
equals(java.lang.Object obj) |
void |
flip(int index) |
void |
forEachBit(kotlin.jvm.functions.Function1<? super java.lang.Integer,kotlin.Unit> f)
Enumerates over all
true bits sequeneially. This function
performs better than forEach and any other functions
from Iterable. |
boolean |
get(int index) |
int[] |
getWords()
(can be manipulated directly)
|
int |
hashCode() |
boolean |
intersects(BitVector other)
Returns true if the specified BitVector has any bits set to true
that are also set to true in this BitVector.
|
boolean |
isEmpty() |
kotlin.collections.IntIterator |
iterator() |
int |
length()
Returns the "logical size" of this bitset: the index of the
highest set bit in the bitset plus one. Returns zero if the
bitset contains no set bits.
|
void |
or(BitVector other)
Performs a logical OR of this bit set with the bit set
argument. This bit set is modified so that a bit in it has the
value
true if and only if it either already had the value true
or the corresponding bit in the bit set argument has the
value true. |
void |
set(int index) |
void |
set(int index,
boolean value) |
void |
setWords(int[] p)
(can be manipulated directly)
|
java.lang.String |
toString() |
void |
unsafeClear(int index) |
boolean |
unsafeGet(int index) |
void |
unsafeSet(int index) |
void |
unsafeSet(int index,
boolean value) |
void |
xor(BitVector other)
Performs a logical XOR of this bit set with the bit set
argument. This bit set is modified so that a bit in it has
the value true if and only if one of the following statements holds:
|
public BitVector()
public BitVector(BitVector copyFrom)
Creates a bit set based off another bit vector.
public int[] getWords()
(can be manipulated directly)
public void setWords(int[] p)
(can be manipulated directly)
public BitVector copy()
public boolean get(int index)
index - the index of the bitpublic void set(int index)
index - the index of the bit to setpublic void set(int index,
boolean value)
index - the index of the bit to setpublic boolean unsafeGet(int index)
index - the index of the bitpublic void unsafeSet(int index)
index - the index of the bit to setpublic void unsafeSet(int index,
boolean value)
index - the index of the bit to setpublic void flip(int index)
index - the index of the bit to flippublic void ensureCapacity(int bits)
Grows the backing array so that it can hold the requested
bits. Mostly applicable when relying on the unsafe methods,
including BitVector.unsafeGet and BitVector.unsafeClear.
bits - number of bits to accomodateBitVector.unsafeGet,
BitVector.unsafeClearpublic void clear(int index)
index - the index of the bit to clearpublic void unsafeClear(int index)
index - the index of the bit to clearpublic void clear()
Clears the entire bitset
public int length()
Returns the "logical size" of this bitset: the index of the highest set bit in the bitset plus one. Returns zero if the bitset contains no set bits.
public boolean isEmpty()
true if this bitset contains no set bitspublic void and(BitVector other)
Performs a logical AND of this target bit set with the argument bit set. This bit set is modified so that each bit in it has the value true if and only if it both initially had the value true and the corresponding bit in the bit set argument also had the value true.
other - a bit setpublic void andNot(BitVector other)
Clears all of the bits in this bit set whose corresponding bit is set in the specified bit set.
other - a bit setpublic void or(BitVector other)
Performs a logical OR of this bit set with the bit set
argument. This bit set is modified so that a bit in it has the
value true if and only if it either already had the value true
or the corresponding bit in the bit set argument has the
value true.
other - a bit setpublic void xor(BitVector other)
Performs a logical XOR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value true if and only if one of the following statements holds:
The bit initially has the value true, and the corresponding bit in
the argument has the value false.
The bit initially has the value false, and the corresponding bit in
the argument has the value true.
other - public boolean intersects(BitVector other)
Returns true if the specified BitVector has any bits set to true that are also set to true in this BitVector.
other - a bit setpublic boolean contains(BitVector other)
Returns true if this bit set is a super set of the specified set, i.e. it has all bits set to true that are also set to true in the specified BitVector.
other - a bit setpublic int cardinality()
Returns the count of true bits
public kotlin.collections.IntIterator iterator()
public int hashCode()
public boolean equals(java.lang.Object obj)
public java.lang.String toString()
public void forEachBit(kotlin.jvm.functions.Function1<? super java.lang.Integer,kotlin.Unit> f)
Enumerates over all true bits sequeneially. This function
performs better than forEach and any other functions
from Iterable.