Documentation of 'cc.redberry.core.utils.BitArray' Java class
BitArray
cc.redberry.core.utils

Class BitArray



  • public class BitArray
    extends java.lang.Object
    This class represents an "array of booleans" with many fast and useful methods. Consumes ~ 8 times less memory than array of booleans for big sizes. Has slightly different semantics than java's built in BitSet and also provides additional functionality like loadValueFrom(BitArray, int, int, int) and copyOfRange(int, int).
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static BitArray EMPTY 
    • Constructor Summary

      Constructors 
      Constructor and Description
      BitArray(boolean[] array)
      Creates a bit array from array of booleans
      BitArray(int size)
      Creates an array with specified size.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void and(BitArray bitArray)
      BitArray append(BitArray other) 
      int bitCount()
      Returns the number of 1 bits.
      void clear(int i)
      Clears the specified bit (sets to 0)
      void clearAll()
      Clears all bits of this bit array
      BitArray clone()
      Returns a clone of this bit array.
      BitArray copyOfRange(int from) 
      BitArray copyOfRange(int from, int to)
      Returns a new bit array, containing values from the specified range
      boolean equals(java.lang.Object o) 
      boolean get(int i)
      Returns the state of specified bit
      int[] getBits()
      Returns an array with positions of all "1" bits.
      int hashCode() 
      boolean intersects(BitArray bitArray)
      Returns true if there are 1 bits in the same positions.
      boolean isEmpty()
      Returns true if all bits in this array are in the 0 state.
      boolean isFull()
      Returns true if all bits in this array are in the 1 state.
      void loadValueFrom(BitArray bitArray)
      Copy values from the array of the same size
      void loadValueFrom(BitArray bitArray, int sourceOffset, int thisOffset, int length)
      Analog of System.arraycopy(Object, int, Object, int, int), where src is bitArray.
      int nextBit(int position)
      Returns the next "1" bit from the specified position.
      int nextZeroBit(int position)
      Returns the next "0" bit from the specified position (inclusively).
      void not()
      Inverts all bits in this bit array
      void or(BitArray bitArray)
      void set(int i)
      Sets the specified bit (sets to 1)
      void set(int i, boolean value)
      Sets the value of specified bit to specified value
      void setAll()
      Sets all bits of this bit array
      void setAll(int[] positions, boolean value)
      Sets values at specified positions to specified value
      void setAll(IntArrayList positions, boolean value)
      Sets values at specified positions to specified value
      int size()
      Returns the length of this bit array
      BitArray times(int times) 
      java.lang.String toString() 
      void xor(BitArray bitArray)
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • EMPTY

        public static final BitArray EMPTY
    • Constructor Detail

      • BitArray

        public BitArray(int size)
        Creates an array with specified size. Initial state of all bits is 0 (cleared).
        Parameters:
        size -
      • BitArray

        public BitArray(boolean[] array)
        Creates a bit array from array of booleans
        Parameters:
        array - boolean array
    • Method Detail

      • not

        public void not()
        Inverts all bits in this bit array
      • bitCount

        public int bitCount()
        Returns the number of 1 bits.
        Returns:
        number of 1 bits
      • clearAll

        public void clearAll()
        Clears all bits of this bit array
      • clone

        public BitArray clone()
        Returns a clone of this bit array.
        Overrides:
        clone in class java.lang.Object
        Returns:
        clone of this bit array
      • intersects

        public boolean intersects(BitArray bitArray)
        Returns true if there are 1 bits in the same positions. Equivalent to !this.and(other).isEmpty()
        Parameters:
        bitArray - other bit array
        Returns:
        true if there are 1 bits in the same positions
      • loadValueFrom

        public void loadValueFrom(BitArray bitArray)
        Copy values from the array of the same size
        Parameters:
        bitArray - bit array to copy values from
      • get

        public boolean get(int i)
        Returns the state of specified bit
        Parameters:
        i - index
        Returns:
        true if bit is set, false if bit is cleared
      • set

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

        public void clear(int i)
        Clears the specified bit (sets to 0)
        Parameters:
        i - index of bit
      • set

        public void set(int i,
                        boolean value)
        Sets the value of specified bit to specified value
        Parameters:
        i - index
        value - value
      • setAll

        public void setAll(int[] positions,
                           boolean value)
        Sets values at specified positions to specified value
        Parameters:
        positions - positions
        value - value
      • setAll

        public void setAll(IntArrayList positions,
                           boolean value)
        Sets values at specified positions to specified value
        Parameters:
        positions - positions
        value - value
      • setAll

        public void setAll()
        Sets all bits of this bit array
      • size

        public int size()
        Returns the length of this bit array
        Returns:
        length of this bit array
      • isFull

        public boolean isFull()
        Returns true if all bits in this array are in the 1 state.
        Returns:
        true if all bits in this array are in the 1 state
      • isEmpty

        public boolean isEmpty()
        Returns true if all bits in this array are in the 0 state.
        Returns:
        true if all bits in this array are in the 0 state
      • getBits

        public int[] getBits()
        Returns an array with positions of all "1" bits.
        Returns:
        array with positions of all "1" bits
      • nextBit

        public int nextBit(int position)
        Returns the next "1" bit from the specified position.
        Parameters:
        position - initial position
        Returns:
        position of the next "1" bit of -1 if all bits after position are 0
      • nextZeroBit

        public int nextZeroBit(int position)
        Returns the next "0" bit from the specified position (inclusively).
        Parameters:
        position - initial position
        Returns:
        position of the next "0" bit of -1 if all bits after position are 0
      • copyOfRange

        public BitArray copyOfRange(int from,
                                    int to)
        Returns a new bit array, containing values from the specified range
        Parameters:
        from - lower bound of range
        to - upper bound of range
        Returns:
        new bit array, containing values from the specified range
      • copyOfRange

        public BitArray copyOfRange(int from)
      • loadValueFrom

        public void loadValueFrom(BitArray bitArray,
                                  int sourceOffset,
                                  int thisOffset,
                                  int length)
        Analog of System.arraycopy(Object, int, Object, int, int), where src is bitArray.
        Parameters:
        bitArray - source
        sourceOffset - source offset
        thisOffset - destination offset
        length - number of bits to copy
      • times

        public BitArray times(int times)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.