public class BitVector extends Object
Performance optimized bitset implementation. Certain operations are
prefixed with unsafe
; these methods perform no validation,
and are primarily leveraged internally to optimize access on entityId bitsets.
Originally adapted from com.badlogic.gdx.utils.Bits
, it has been
renamed to avoid namespace confusion.
EntityManager.registerEntityStore(BitVector)
Constructor and Description |
---|
BitVector() |
BitVector(BitVector copyFrom)
Creates a bit set based off another bit vector.
|
BitVector(int nbits)
Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through
nbits-1.
|
Modifier and Type | Method and Description |
---|---|
void |
and(BitVector other)
Performs a logical AND of this target bit set with the argument bit set.
|
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() |
void |
clear()
Clears the entire bitset
|
void |
clear(int index) |
boolean |
containsAll(BitVector other)
Returns true if this bit set is a super set of the specified set,
i.e.
|
void |
ensureCapacity(int bits)
Grows the backing array (
long[] ) so that it can hold the requested
bits. |
boolean |
equals(Object obj) |
void |
flip(int index) |
boolean |
get(int index) |
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() |
int |
length()
Returns the "logical size" of this bitset: the index of the highest set bit in the bitset plus one.
|
int |
nextClearBit(int fromIndex)
Returns the index of the first bit that is set to false that occurs on or after the specified starting index.
|
int |
nextSetBit(int fromIndex)
Returns the index of the first bit that is set to true that occurs on or after the specified starting index.
|
void |
or(BitVector other)
Performs a logical OR of this bit set with the bit set argument.
|
void |
set(int index) |
void |
set(int index,
boolean value) |
IntBag |
toIntBag(IntBag out)
Decodes the set bits as integers.
|
IntBag |
toIntBagIdCid(ComponentManager cm,
IntBag out)
Decodes the set bits as pairs of
entity id and
compositionId . |
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.
|
public BitVector()
public BitVector(int nbits)
nbits
- the initial size of the bit setpublic BitVector(BitVector copyFrom)
copyFrom
- public boolean get(int index)
index
- the index of the bitArrayIndexOutOfBoundsException
- if index < 0public void set(int index)
index
- the index of the bit to setArrayIndexOutOfBoundsException
- if index < 0public void set(int index, boolean value)
index
- the index of the bit to setArrayIndexOutOfBoundsException
- if index < 0public boolean unsafeGet(int index)
index
- the index of the bitArrayIndexOutOfBoundsException
- if index < 0 or index >= words.length>>public void unsafeSet(int index)
index
- the index of the bit to setArrayIndexOutOfBoundsException
- if index < 0 or index >= words.lengthpublic void unsafeSet(int index, boolean value)
index
- the index of the bit to setArrayIndexOutOfBoundsException
- if index < 0 or index >= words.lengthpublic void flip(int index)
index
- the index of the bit to flippublic void ensureCapacity(int bits)
long[]
) so that it can hold the requested
bits. Mostly applicable when relying on the unsafe
methods,
including unsafeGet(int)
and unsafeClear(int)
.bits
- number of bits to accomodatepublic void clear(int index)
index
- the index of the bit to clearArrayIndexOutOfBoundsException
- if index < 0public void unsafeClear(int index)
index
- the index of the bit to clearArrayIndexOutOfBoundsException
- if index < 0 or index >= words.lengthpublic void clear()
public int length()
public boolean isEmpty()
public int nextSetBit(int fromIndex)
public int nextClearBit(int fromIndex)
public void and(BitVector other)
other
- a bit setpublic void andNot(BitVector other)
other
- a bit setpublic void or(BitVector other)
other
- a bit setpublic void xor(BitVector other)
other
- public boolean intersects(BitVector other)
other
- a bit setpublic boolean containsAll(BitVector other)
other
- a bit setpublic int cardinality()
public IntBag toIntBag(IntBag out)
IntBag
is reset before the bits are transposed.out
- decoded ints end up herepublic IntBag toIntBagIdCid(ComponentManager cm, IntBag out)
entity id
and
compositionId
. The
destinationIntBag
is reset before the bits are
transposed.out
- decoded ints end up hereCopyright © 2019. All rights reserved.