- All Known Implementing Classes:
BitVector32,BitVector64
public interface BitVector
This interface defines the behavior of bit vectors, i.e., fixed-sized vectors with single bit elements. This is
similar to the standard Java class
BitSet, which implements variable-sized vectors and additional
functionality.-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]binarize(byte[] b) Binarizes the specifiedbyte[]by replacing all non-zero values by 1.static BitVectorcreate(int length) Creates and returns a new bitvector of typeBitVector64with the specified length.static BitVectorfrom(boolean[] bools) Creates and returns a new bitvector of typeBitVector64from the specifiedbooleanarray, setting elements to 0/false or 1/true.static BitVectorfrom(byte[] bytes) Creates and returns a new bitvector of typeBitVector64from the specifiedbytearray.booleanget(int i) Returnstrueis the specified bit-element is set (1),falseotherwise (0).intReturns the length of this bit vector.voidset(int i) Sets the specified element (to bit-value 1).default voidset(int i, boolean val) Sets the specified bit-element to the given boolean value (1 fortrue, 0 forfalse).voidsetAll()Sets all element values to 1.default boolean[]Returns the contents of this bit vector as abooleanarray.default byte[]Returns the contents of this bit vector as abytearray.voidunset(int i) Unsets the specified element (to bit-value 0).voidunsetAll()Sets all element values to 0.
-
Method Details
-
get
Returnstrueis the specified bit-element is set (1),falseotherwise (0).- Parameters:
i- the element index- Returns:
- as described
-
set
Sets the specified bit-element to the given boolean value (1 fortrue, 0 forfalse).- Parameters:
i- the element indexval- a boolean value
-
set
Sets the specified element (to bit-value 1).- Parameters:
i- the element index
-
unset
Unsets the specified element (to bit-value 0).- Parameters:
i- the element index
-
setAll
void setAll()Sets all element values to 1. -
unsetAll
void unsetAll()Sets all element values to 0. -
getLength
int getLength()Returns the length of this bit vector.- Returns:
- the length of this bit vector
-
toByteArray
Returns the contents of this bit vector as abytearray. Bit-value 0 maps to byte value 0, value 1 maps to 1.- Returns:
- a
bytearray
-
toBooleanArray
Returns the contents of this bit vector as abooleanarray. Bit-value 0 maps to false, value 1 maps to true.- Returns:
- a
booleanarray
-
from
Creates and returns a new bitvector of typeBitVector64from the specifiedbytearray. Each byte element b is interpreted as 0/false if b = 0 and 1/true otherwise.- Parameters:
bytes- an array of byte values- Returns:
- a new bit vector
-
from
Creates and returns a new bitvector of typeBitVector64from the specifiedbooleanarray, setting elements to 0/false or 1/true.- Parameters:
bools- an array of boolean values- Returns:
- a new bit vector
-
create
Creates and returns a new bitvector of typeBitVector64with the specified length. Elements are initialized to 0/false.- Parameters:
length- the length of the bit vector- Returns:
- a new bit vector
-
binarize
Binarizes the specifiedbyte[]by replacing all non-zero values by 1. Returns a new array, the original array is not modified.- Parameters:
b- abyte[]- Returns:
- a new
byte[]with values 0/1 only
-