Class RegularBitSet

java.lang.Object
pascal.taie.util.collection.AbstractBitSet
pascal.taie.util.collection.RegularBitSet
All Implemented Interfaces:
Serializable, IBitSet, Copyable<IBitSet>

public class RegularBitSet extends AbstractBitSet implements Serializable
Regular bit set implementation. This implementation is very similar to Set which uses a long[] to store all the set bits.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface pascal.taie.util.collection.IBitSet

    IBitSet.Action<R>
  • Field Summary

    Fields inherited from class pascal.taie.util.collection.AbstractBitSet

    ADDRESS_BITS_PER_WORD, BITS_PER_WORD
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new bit set.
    RegularBitSet(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.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    and(IBitSet set)
    Performs a logical AND of this target bit set with the argument bit set.
    boolean
    Clears all of the bits in this BitSet whose corresponding bit is set in the specified BitSet.
    int
    Returns the number of bits set to true in this BitSet.
    void
    Sets all of the bits in this BitSet to false.
    boolean
    clear(int bitIndex)
    Sets the bit specified by the index to false.
    boolean
    Returns true if this BitSet contains all set bits in the specified BitSet.
    Creates and returns a copy of this object.
    boolean
    Compares this object against the specified object.
    void
    flip(int bitIndex)
    Sets the bit at the specified index to the complement of its current value.
    boolean
    get(int bitIndex)
    Returns the value of the bit with the specified index.
    int
    Returns the hash code value for this bit set.
    boolean
    Returns true if the specified BitSet has any bits set to true that are also set to true in this BitSet.
    boolean
    Returns true if this BitSet contains no bits that are set to true.
    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.
    boolean
    or(IBitSet set)
    Performs a logical OR of this bit set with the bit set argument.
    Performs a logical OR of this bit set with the bit set argument, computes and returns the difference set between given bit set and this set (before performing logical OR).
    int
    previousClearBit(int fromIndex)
    Returns the index of the nearest bit that is set to false that occurs on or before the specified starting index.
    int
    previousSetBit(int fromIndex)
    Returns the index of the nearest bit that is set to true that occurs on or before the specified starting index.
    boolean
    set(int bitIndex)
    Sets the bit at the specified index to true.
    void
    Sets the content of this bit set to the same as specified bit set.
    int
    Returns the number of bits of space actually in use by this BitSet to represent bit values.
    boolean
    xor(IBitSet set)
    Performs a logical XOR of this bit set with the bit set argument.

    Methods inherited from class pascal.taie.util.collection.AbstractBitSet

    disjoints, set, toString, wordIndex

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface pascal.taie.util.collection.IBitSet

    iterateBits
  • Constructor Details

    • RegularBitSet

      public RegularBitSet()
      Creates a new bit set. All bits are initially false.
    • RegularBitSet

      public RegularBitSet(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. All bits are initially false.
      Parameters:
      nbits - the initial size of the bit set
      Throws:
      NegativeArraySizeException - if the specified initial size is negative
  • Method Details

    • set

      public boolean set(int bitIndex)
      Description copied from interface: IBitSet
      Sets the bit at the specified index to true.
      Specified by:
      set in interface IBitSet
      Parameters:
      bitIndex - a bit index
      Returns:
      true if this BitSet changed as a result of the call
    • clear

      public boolean clear(int bitIndex)
      Description copied from interface: IBitSet
      Sets the bit specified by the index to false.
      Specified by:
      clear in interface IBitSet
      Parameters:
      bitIndex - the index of the bit to be cleared
      Returns:
      true if this BitSet changed as a result of the call
    • get

      public boolean get(int bitIndex)
      Description copied from interface: IBitSet
      Returns the value of the bit with the specified index. The value is true if the bit with the index bitIndex is currently set in this BitSet; otherwise, the result is false.
      Specified by:
      get in interface IBitSet
      Parameters:
      bitIndex - the bit index
      Returns:
      the value of the bit with the specified index
    • flip

      public void flip(int bitIndex)
      Description copied from interface: IBitSet
      Sets the bit at the specified index to the complement of its current value. This operation must modify the BitSet.
      Specified by:
      flip in interface IBitSet
      Parameters:
      bitIndex - the index of the bit to flip
    • nextSetBit

      public int nextSetBit(int fromIndex)
      Description copied from interface: IBitSet
      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.

      To iterate over the true bits in a BitSet, use the following loop:

       
       for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {
           // operate on index i here
           if (i == Integer.MAX_VALUE) {
               break; // or (i+1) would overflow
           }
       }
      Specified by:
      nextSetBit in interface IBitSet
      Parameters:
      fromIndex - the index to start checking from (inclusive)
      Returns:
      the index of the next set bit, or -1 if there is no such bit
    • nextClearBit

      public int nextClearBit(int fromIndex)
      Description copied from interface: IBitSet
      Returns the index of the first bit that is set to false that occurs on or after the specified starting index.
      Specified by:
      nextClearBit in interface IBitSet
      Parameters:
      fromIndex - the index to start checking from (inclusive)
      Returns:
      the index of the next clear bit
    • previousSetBit

      public int previousSetBit(int fromIndex)
      Description copied from interface: IBitSet
      Returns the index of the nearest bit that is set to true that occurs on or before the specified starting index. If no such bit exists, or if -1 is given as the starting index, then -1 is returned.

      To iterate over the true bits in a BitSet, use the following loop:

       
       for (int i = bs.length(); (i = bs.previousSetBit(i-1)) >= 0; ) {
           // operate on index i here
       }
      Specified by:
      previousSetBit in interface IBitSet
      Parameters:
      fromIndex - the index to start checking from (inclusive)
      Returns:
      the index of the previous set bit, or -1 if there is no such bit
    • previousClearBit

      public int previousClearBit(int fromIndex)
      Description copied from interface: IBitSet
      Returns the index of the nearest bit that is set to false that occurs on or before the specified starting index. If no such bit exists, or if -1 is given as the starting index, then -1 is returned.
      Specified by:
      previousClearBit in interface IBitSet
      Parameters:
      fromIndex - the index to start checking from (inclusive)
      Returns:
      the index of the previous clear bit, or -1 if there is no such bit
    • intersects

      public boolean intersects(IBitSet set)
      Description copied from interface: IBitSet
      Returns true if the specified BitSet has any bits set to true that are also set to true in this BitSet.
      Specified by:
      intersects in interface IBitSet
      Overrides:
      intersects in class AbstractBitSet
      Parameters:
      set - BitSet to intersect with
      Returns:
      boolean indicating whether this BitSet intersects the specified BitSet
    • contains

      public boolean contains(IBitSet set)
      Description copied from interface: IBitSet
      Returns true if this BitSet contains all set bits in the specified BitSet.
      Specified by:
      contains in interface IBitSet
      Overrides:
      contains in class AbstractBitSet
      Parameters:
      set - bit set to be checked for containment in this set.
      Returns:
      boolean indicating whether this BitSet contains all set bits in the specified BitSet
    • and

      public boolean and(IBitSet set)
      Description copied from interface: IBitSet
      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.
      Specified by:
      and in interface IBitSet
      Parameters:
      set - a bit set
      Returns:
      true if this bit set changed as a result of the call
    • andNot

      public boolean andNot(IBitSet set)
      Description copied from interface: IBitSet
      Clears all of the bits in this BitSet whose corresponding bit is set in the specified BitSet.
      Specified by:
      andNot in interface IBitSet
      Overrides:
      andNot in class AbstractBitSet
      Parameters:
      set - the BitSet with which to mask this BitSet
      Returns:
      true if this bit set changed as a result of the call
    • or

      public boolean or(IBitSet set)
      Description copied from interface: IBitSet
      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.
      Specified by:
      or in interface IBitSet
      Overrides:
      or in class AbstractBitSet
      Parameters:
      set - a bit set
      Returns:
      true if this bit set changed as a result of the call
    • orDiff

      public IBitSet orDiff(IBitSet set)
      Description copied from interface: IBitSet
      Performs a logical OR of this bit set with the bit set argument, computes and returns the difference set between given bit set and this set (before performing logical OR).
      Specified by:
      orDiff in interface IBitSet
      Overrides:
      orDiff in class AbstractBitSet
      Parameters:
      set - a bit set.
      Returns:
      a new bit set of bit values that are present in the bit set argument and were absent in this bit set before.
    • xor

      public boolean xor(IBitSet set)
      Description copied from interface: IBitSet
      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.
      Specified by:
      xor in interface IBitSet
      Overrides:
      xor in class AbstractBitSet
      Parameters:
      set - a bit set
      Returns:
      true if this bit set changed as a result of the call
    • setTo

      public void setTo(IBitSet set)
      Description copied from interface: IBitSet
      Sets the content of this bit set to the same as specified bit set.
      Specified by:
      setTo in interface IBitSet
      Overrides:
      setTo in class AbstractBitSet
      Parameters:
      set - a bit set
    • clear

      public void clear()
      Description copied from interface: IBitSet
      Sets all of the bits in this BitSet to false.
      Specified by:
      clear in interface IBitSet
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: IBitSet
      Returns true if this BitSet contains no bits that are set to true.
      Specified by:
      isEmpty in interface IBitSet
      Returns:
      boolean indicating whether this BitSet is empty
    • length

      public int length()
      Description copied from interface: IBitSet
      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.
      Specified by:
      length in interface IBitSet
      Returns:
      the logical size of this BitSet
    • size

      public int size()
      Description copied from interface: IBitSet
      Returns the number of bits of space actually in use by this BitSet to represent bit values. The maximum element in the set is the size - 1st element.
      Specified by:
      size in interface IBitSet
      Returns:
      the number of bits currently in this bit set
    • cardinality

      public int cardinality()
      Description copied from interface: IBitSet
      Returns the number of bits set to true in this BitSet.
      Specified by:
      cardinality in interface IBitSet
      Returns:
      the number of bits set to true in this BitSet
    • hashCode

      public int hashCode()
      Returns the hash code value for this bit set. The hash code depends only on which bits are set within this BitSet.

      The hash code is defined to be the result of the following calculation:

       
       public int hashCode() {
           long h = 1234;
           long[] words = toLongArray();
           for (int i = words.length; --i >= 0; )
               h ^= words[i] * (i + 1);
           return (int)((h >> 32) ^ h);
       }
      Note that the hash code changes if the set of bits is altered.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this bit set
    • equals

      public boolean equals(Object obj)
      Compares this object against the specified object. The result is true if and only if the argument is not null and is a BitSet object that has exactly the same set of bits set to true as this bit set. That is, for every nonnegative int index k,
      ((BitSet)obj).get(k) == this.get(k)
      must be true. The current sizes of the two bit sets are not compared.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare with
      Returns:
      true if the objects are the same; false otherwise
      See Also:
    • copy

      public RegularBitSet copy()
      Description copied from interface: Copyable
      Creates and returns a copy of this object.
      Specified by:
      copy in interface Copyable<IBitSet>
      Returns:
      a copy of this object.