Class BitArray

java.lang.Object
org.basex.util.BitArray

public final class BitArray extends Object
Bit array that grows when needed. The implementation is similar to BitSet.
Author:
BaseX Team 2005-21, BSD License, Dimitar Popov
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new bit array.
    BitArray(int capacity, boolean set)
    Constructs a new bit array and an initial value.
    BitArray(long[] array, int nr)
    Constructs a new bit array with the specified backing array.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of bits set to true.
    void
    clear(int i)
    Sets the ith bit to 0.
    boolean
    get(int i)
    Gets the value of the ith bit.
    int
    Gets the index of the first clear bit.
    int
    nextSet(int i)
    Gets the next bit set to 1, starting from the ith bit.
    void
    set(int i)
    Sets the ith bit to 1.
    long[]
    The word array used to store the bits.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BitArray

      public BitArray(long[] array, int nr)
      Constructs a new bit array with the specified backing array.
      Parameters:
      array - array with bits
      nr - number of used bits
    • BitArray

      public BitArray()
      Constructs a new bit array.
    • BitArray

      public BitArray(int capacity, boolean set)
      Constructs a new bit array and an initial value.
      Parameters:
      capacity - initial number of bits
      set - sets or clears all values
  • Method Details

    • toArray

      public long[] toArray()
      The word array used to store the bits. The array is shrunk to the last word, where a bit is set.
      Returns:
      array of longs
    • cardinality

      public int cardinality()
      Returns the number of bits set to true.
      Returns:
      number of bits set to true
    • get

      public boolean get(int i)
      Gets the value of the ith bit.
      Parameters:
      i - index of the bit
      Returns:
      true if the ith bit is set
    • set

      public void set(int i)
      Sets the ith bit to 1.
      Parameters:
      i - index of the bit
    • clear

      public void clear(int i)
      Sets the ith bit to 0.
      Parameters:
      i - index of the bit
    • nextFree

      public int nextFree()
      Gets the index of the first clear bit.
      Returns:
      index
    • nextSet

      public int nextSet(int i)
      Gets the next bit set to 1, starting from the ith bit.
      Parameters:
      i - index from which to start the search (inclusive)
      Returns:
      index of the next set bit after the ith bit
    • toString

      public String toString()
      Overrides:
      toString in class Object