Class BitArray


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

      Constructors 
      Constructor Description
      BitArray()
      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.
    • Constructor Detail

      • 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 Detail

      • 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