Class BitVector

java.lang.Object
com.prineside.tdi2.utils.BitVector
All Implemented Interfaces:
com.esotericsoftware.kryo.KryoSerializable

public final class BitVector extends Object implements com.esotericsoftware.kryo.KryoSerializable
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    long[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    BitVector(int nbits)
    Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through nbits-1.
    BitVector(BitVector copyFrom)
    Creates a bit set based off another bit vector.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    and(BitVector other)
    Performs a logical AND of this target bit set with the argument bit set.
    void
    Clears all of the bits in this bit set whose corresponding bit is set in the specified bit set.
    int
     
    void
    Clears the entire bitset
    void
    clear(int index)
     
    boolean
    Returns true if this bit set is a super set of the specified set, i.e.
    void
    ensureCapacity(int bits)
    Grows the backing array (long[]) so that it can hold the requested bits.
    boolean
     
    boolean
     
    void
    flip(int index)
     
    boolean
    get(int index)
     
    int
     
    int
     
    boolean
    Returns true if the specified BitVector has any bits set to true that are also set to true in this BitVector.
    boolean
     
    int
    Returns the "logical size" of this bitset: the index of the highest set bit in the bitset plus one.
    int
    nextClearBit(int fromIndex)
    Returns the index of the first bit that is set to false that occurs on or after the specified starting index.
    int
    nextSetBit(int fromIndex)
    Returns the index of the first bit that is set to true that occurs on or after the specified starting index.
    void
    or(BitVector other)
    Performs a logical OR of this bit set with the bit set argument.
    void
    read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input)
     
    void
    set(int index)
     
    void
    set(int index, boolean value)
     
     
    void
    unsafeClear(int index)
     
    boolean
    unsafeGet(int index)
     
    void
    unsafeSet(int index)
     
    void
    unsafeSet(int index, boolean value)
     
    void
    write(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output)
     
    void
    xor(BitVector other)
    Performs a logical XOR of this bit set with the bit set argument.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • words

      public long[] words
  • Constructor Details

    • BitVector

      public BitVector()
    • BitVector

      public BitVector(int nbits)
      Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through nbits-1.
      Parameters:
      nbits - the initial size of the bit set
    • BitVector

      public BitVector(BitVector copyFrom)
      Creates a bit set based off another bit vector.
      Parameters:
      copyFrom -
  • Method Details

    • write

      public void write(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output)
      Specified by:
      write in interface com.esotericsoftware.kryo.KryoSerializable
    • read

      public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input)
      Specified by:
      read in interface com.esotericsoftware.kryo.KryoSerializable
    • get

      public boolean get(int index)
      Parameters:
      index - the index of the bit
      Returns:
      whether the bit is set
      Throws:
      ArrayIndexOutOfBoundsException - if index < 0
    • getCapacity

      public int getCapacity()
    • set

      public void set(int index)
      Parameters:
      index - the index of the bit to set
      Throws:
      ArrayIndexOutOfBoundsException - if index < 0
    • set

      public void set(int index, boolean value)
      Parameters:
      index - the index of the bit to set
      Throws:
      ArrayIndexOutOfBoundsException - if index < 0
    • unsafeGet

      public boolean unsafeGet(int index)
      Parameters:
      index - the index of the bit
      Returns:
      whether the bit is set
      Throws:
      ArrayIndexOutOfBoundsException - if index < 0 or index >= words.length</></>
    • unsafeSet

      public void unsafeSet(int index)
      Parameters:
      index - the index of the bit to set
      Throws:
      ArrayIndexOutOfBoundsException - if index < 0 or index >= words.length
    • unsafeSet

      public void unsafeSet(int index, boolean value)
      Parameters:
      index - the index of the bit to set
      Throws:
      ArrayIndexOutOfBoundsException - if index < 0 or index >= words.length
    • flip

      public void flip(int index)
      Parameters:
      index - the index of the bit to flip
    • ensureCapacity

      public void ensureCapacity(int bits)
      Grows the backing array (long[]) so that it can hold the requested bits. Mostly applicable when relying on the unsafe methods, including unsafeGet(int) and unsafeClear(int).
      Parameters:
      bits - number of bits to accomodate
    • clear

      public void clear(int index)
      Parameters:
      index - the index of the bit to clear
      Throws:
      ArrayIndexOutOfBoundsException - if index < 0
    • unsafeClear

      public void unsafeClear(int index)
      Parameters:
      index - the index of the bit to clear
      Throws:
      ArrayIndexOutOfBoundsException - if index < 0 or index >= words.length
    • clear

      public void clear()
      Clears the entire bitset
    • length

      public int length()
      Returns the "logical size" of this bitset: the index of the highest set bit in the bitset plus one. Returns zero if the bitset contains no set bits.
      Returns:
      the logical size of this bitset
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if this bitset contains no bits that are set to true
    • nextSetBit

      public int nextSetBit(int fromIndex)
      Returns the index of the first bit that is set to true that occurs on or after the specified starting index. If no such bit exists then -1 is returned.
    • nextClearBit

      public int nextClearBit(int fromIndex)
      Returns the index of the first bit that is set to false that occurs on or after the specified starting index.
    • and

      public void and(BitVector other)
      Performs a logical AND of this target bit set with the argument bit set. This bit set is modified so that each bit in it has the value true if and only if it both initially had the value true and the corresponding bit in the bit set argument also had the value true.
      Parameters:
      other - a bit set
    • andNot

      public void andNot(BitVector other)
      Clears all of the bits in this bit set whose corresponding bit is set in the specified bit set.
      Parameters:
      other - a bit set
    • or

      public void or(BitVector other)
      Performs a logical OR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value true if and only if it either already had the value true or the corresponding bit in the bit set argument has the value true.
      Parameters:
      other - a bit set
    • xor

      public void xor(BitVector other)
      Performs a logical XOR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value true if and only if one of the following statements holds:
      • The bit initially has the value true, and the corresponding bit in the argument has the value false.
      • The bit initially has the value false, and the corresponding bit in the argument has the value true.
      Parameters:
      other -
    • intersects

      public boolean intersects(BitVector other)
      Returns true if the specified BitVector has any bits set to true that are also set to true in this BitVector.
      Parameters:
      other - a bit set
      Returns:
      boolean indicating whether this bit set intersects the specified bit set
    • containsAll

      public boolean containsAll(BitVector other)
      Returns true if this bit set is a super set of the specified set, i.e. it has all bits set to true that are also set to true in the specified BitVector.
      Parameters:
      other - a bit set
      Returns:
      boolean indicating whether this bit set is a super set of the specified set
    • cardinality

      public int cardinality()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • exactlyTheSame

      public boolean exactlyTheSame(BitVector vector)
    • toString

      public String toString()
      Overrides:
      toString in class Object