Interface BitVector

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 Type
    Method
    Description
    static byte[]
    binarize(byte[] b)
    Binarizes the specified byte[] by replacing all non-zero values by 1.
    static BitVector
    create(int length)
    Creates and returns a new bitvector of type BitVector64 with the specified length.
    static BitVector
    from(boolean[] bools)
    Creates and returns a new bitvector of type BitVector64 from the specified boolean array, setting elements to 0/false or 1/true.
    static BitVector
    from(byte[] bytes)
    Creates and returns a new bitvector of type BitVector64 from the specified byte array.
    boolean
    get(int i)
    Returns true 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 for true, 0 for false).
    void
    Sets all element values to 1.
    default boolean[]
    Returns the contents of this bit vector as a boolean array.
    default byte[]
    Returns the contents of this bit vector as a byte array.
    void
    unset(int i)
    Unsets the specified element (to bit-value 0).
    void
    Sets all element values to 0.
  • Method Details

    • get

      boolean get(int i)
      Returns true is the specified bit-element is set (1), false otherwise (0).
      Parameters:
      i - the element index
      Returns:
      as described
    • set

      default void set(int i, boolean val)
      Sets the specified bit-element to the given boolean value (1 for true, 0 for false).
      Parameters:
      i - the element index
      val - a boolean value
    • set

      void set(int i)
      Sets the specified element (to bit-value 1).
      Parameters:
      i - the element index
    • unset

      void unset(int i)
      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

      default byte[] toByteArray()
      Returns the contents of this bit vector as a byte array. Bit-value 0 maps to byte value 0, value 1 maps to 1.
      Returns:
      a byte array
    • toBooleanArray

      default boolean[] toBooleanArray()
      Returns the contents of this bit vector as a boolean array. Bit-value 0 maps to false, value 1 maps to true.
      Returns:
      a boolean array
    • from

      static BitVector from(byte[] bytes)
      Creates and returns a new bitvector of type BitVector64 from the specified byte 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

      static BitVector from(boolean[] bools)
      Creates and returns a new bitvector of type BitVector64 from the specified boolean array, setting elements to 0/false or 1/true.
      Parameters:
      bools - an array of boolean values
      Returns:
      a new bit vector
    • create

      static BitVector create(int length)
      Creates and returns a new bitvector of type BitVector64 with the specified length. Elements are initialized to 0/false.
      Parameters:
      length - the length of the bit vector
      Returns:
      a new bit vector
    • binarize

      static byte[] binarize(byte[] b)
      Binarizes the specified byte[] by replacing all non-zero values by 1. Returns a new array, the original array is not modified.
      Parameters:
      b - a byte[]
      Returns:
      a new byte[] with values 0/1 only