Class BitVector

  • All Implemented Interfaces:
    Cloneable

    public class BitVector
    extends Object
    implements Cloneable
    A vector (array) of bits that is accessed in units ("registers") of width bits which are stored as 64bit "words" (longs). In this context a register is at most 64bits.
    • Constructor Detail

      • BitVector

        public BitVector​(int width,
                         long count)
        Parameters:
        width - the width of each register. This cannot be negative or zero or greater than 63 (the signed word size).
        count - the number of registers. This cannot be negative or zero
    • Method Detail

      • words

        public final long[] words()
      • wordCount

        public final int wordCount()
      • byteCount

        public final int byteCount()
      • registerWidth

        public final int registerWidth()
      • getRegister

        public long getRegister​(long registerIndex)
        Parameters:
        registerIndex - the index of the register whose value is to be retrieved. This cannot be negative.
        Returns:
        the value at the specified register index
        See Also:
        setRegister(long, long), setMaxRegister(long, long)
      • setRegister

        public void setRegister​(long registerIndex,
                                long value)
        Parameters:
        registerIndex - the index of the register whose value is to be set. This cannot be negative
        value - the value to set in the register
        See Also:
        getRegister(long), setMaxRegister(long, long)
      • registerIterator

        public LongIterator registerIterator()
        Returns:
        a LongIterator for iterating starting at the register with index zero. This will never be null.
      • setMaxRegister

        public boolean setMaxRegister​(long registerIndex,
                                      long value)
        Sets the value of the specified index register if and only if the specified value is greater than the current value in the register. This is equivalent to but much more performant than:

        vector.setRegister(index, Math.max(vector.getRegister(index), value));
        Parameters:
        registerIndex - the index of the register whose value is to be set. This cannot be negative
        value - the value to set in the register if and only if this value is greater than the current value in the register
        Returns:
        true if and only if the specified value is greater than or equal to the current register value. false otherwise.
        See Also:
        getRegister(long), setRegister(long, long), Math.max(long, long)
      • fill

        public void fill​(long val)
        Fills this bit vector with the specified bit value. This can be used to clear the vector by specifying 0.
        Parameters:
        val - the value to set all bits to (only the lowest bit is used)
      • getRegisterContents

        public void getRegisterContents​(IWordSerializer serializer)
        Serializes the registers of the vector using the specified serializer.
        Parameters:
        serializer - the serializer to use. This cannot be null.