- 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 BitVector
create
(int length) Creates and returns a new bitvector of typeBitVector64
with the specified length.static BitVector
from
(boolean[] bools) Creates and returns a new bitvector of typeBitVector64
from the specifiedboolean
array, setting elements to 0/false or 1/true.static BitVector
from
(byte[] bytes) Creates and returns a new bitvector of typeBitVector64
from the specifiedbyte
array.boolean
get
(int i) Returnstrue
is the specified bit-element is set (1),false
otherwise (0).int
Returns the length of this bit vector.void
set
(int i) Sets the specified element (to bit-value 1).default void
set
(int i, boolean val) Sets the specified bit-element to the given boolean value (1 fortrue
, 0 forfalse
).void
setAll()
Sets all element values to 1.default boolean[]
Returns the contents of this bit vector as aboolean
array.default byte[]
Returns the contents of this bit vector as abyte
array.void
unset
(int i) Unsets the specified element (to bit-value 0).void
unsetAll()
Sets all element values to 0.
-
Method Details
-
get
Returnstrue
is the specified bit-element is set (1),false
otherwise (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 abyte
array. Bit-value 0 maps to byte value 0, value 1 maps to 1.- Returns:
- a
byte
array
-
toBooleanArray
Returns the contents of this bit vector as aboolean
array. Bit-value 0 maps to false, value 1 maps to true.- Returns:
- a
boolean
array
-
from
Creates and returns a new bitvector of typeBitVector64
from the specifiedbyte
array. 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 typeBitVector64
from the specifiedboolean
array, 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 typeBitVector64
with 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
-