Class BitSet

java.lang.Object
org.antlr.misc.BitSet
All Implemented Interfaces:
Cloneable, IntSet

public class BitSet extends Object implements IntSet, Cloneable
A BitSet to replace java.util.BitSet. Primary differences are that most set operators return new sets as opposed to oring and anding "in place". Further, a number of operations were added. I cannot contain a BitSet because there is no way to access the internal bits (which I need for speed) and, because it is final, I cannot subclass to add functionality. Consider defining set degree. Without access to the bits, I must call a method n times to test the ith bit...ack! Also seems like or() from util is wrong when size of incoming set is bigger than this.bits.length.
  • Field Details

  • Constructor Details

    • BitSet

      public BitSet()
      Construct a bitset of size one word (64 bits)
    • BitSet

      public BitSet(long[] bits_)
      Construction from a static array of longs
    • BitSet

      public BitSet(int nbits)
      Construct a bitset given the size
      Parameters:
      nbits - The size of the bitset in bits
  • Method Details

    • add

      public void add(int el)
      or this element into this set (grow as necessary to accommodate)
      Specified by:
      add in interface IntSet
    • addAll

      public void addAll(IntSet set)
      Description copied from interface: IntSet
      Add all elements from incoming set to this set. Can limit to set of its own type.
      Specified by:
      addAll in interface IntSet
    • addAll

      public void addAll(int[] elements)
    • addAll

      public void addAll(Iterable<Integer> elements)
    • and

      public IntSet and(IntSet a)
      Description copied from interface: IntSet
      Return the intersection of this set with the argument, creating a new set.
      Specified by:
      and in interface IntSet
    • andInPlace

      public void andInPlace(BitSet a)
    • bitMask

      private static long bitMask(int bitNumber)
    • clear

      public void clear()
    • clear

      public void clear(int el)
    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • size

      public int size()
      Description copied from interface: IntSet
      Return the size of this set (not the underlying implementation's allocated memory size, for example).
      Specified by:
      size in interface IntSet
    • equals

      public boolean equals(Object other)
      Specified by:
      equals in interface IntSet
      Overrides:
      equals in class Object
    • growToInclude

      public void growToInclude(int bit)
      Grows the set to a larger number of bits.
      Parameters:
      bit - element that must fit in set
    • member

      public boolean member(int el)
      Specified by:
      member in interface IntSet
    • getSingleElement

      public int getSingleElement()
      Get the first element you find and return it. Return Label.INVALID otherwise.
      Specified by:
      getSingleElement in interface IntSet
    • isNil

      public boolean isNil()
      Specified by:
      isNil in interface IntSet
    • complement

      public IntSet complement()
    • complement

      public IntSet complement(IntSet set)
      Specified by:
      complement in interface IntSet
    • notInPlace

      public void notInPlace()
    • notInPlace

      public void notInPlace(int maxBit)
      complement bits in the range 0..maxBit.
    • notInPlace

      public void notInPlace(int minBit, int maxBit)
      complement bits in the range minBit..maxBit.
    • numWordsToHold

      private int numWordsToHold(int el)
    • of

      public static BitSet of(int el)
    • of

      public static BitSet of(Collection<? extends Integer> elements)
    • of

      public static BitSet of(IntSet set)
    • of

      public static BitSet of(Map<? extends Integer,?> elements)
    • range

      public static BitSet range(int a, int b)
    • or

      public IntSet or(IntSet a)
      return this | a in a new set
      Specified by:
      or in interface IntSet
    • orInPlace

      public void orInPlace(BitSet a)
    • remove

      public void remove(int el)
      Description copied from interface: IntSet
      remove this element from this set
      Specified by:
      remove in interface IntSet
    • setSize

      private void setSize(int nwords)
      Sets the size of a set.
      Parameters:
      nwords - how many words the new set should be
    • numBits

      public int numBits()
    • lengthInLongWords

      public int lengthInLongWords()
      return how much space is being used by the bits array not how many actually have member bits on.
    • subset

      public boolean subset(BitSet a)
      Is this contained within a?
    • subtractInPlace

      public void subtractInPlace(BitSet a)
      Subtract the elements of 'a' from 'this' in-place. Basically, just turn off all bits of 'this' that are in 'a'.
    • subtract

      public IntSet subtract(IntSet a)
      Specified by:
      subtract in interface IntSet
    • toList

      public List<Integer> toList()
      Specified by:
      toList in interface IntSet
    • toArray

      public int[] toArray()
    • toPackedArray

      public long[] toPackedArray()
    • toString

      public String toString()
      Specified by:
      toString in interface IntSet
      Overrides:
      toString in class Object
    • toString

      public String toString(Grammar g)
      Transform a bit set into a string by formatting each element as an integer separator The string to put in between elements
      Specified by:
      toString in interface IntSet
      Returns:
      A commma-separated list of values
    • toString

      public String toString(String separator, List<String> vocabulary)
      Create a string representation where instead of integer elements, the ith element of vocabulary is displayed instead. Vocabulary is a Vector of Strings. separator The string to put in between elements
      Returns:
      A commma-separated list of character constants.
    • toStringOfHalfWords

      public String toStringOfHalfWords()
      Dump a comma-separated list of the words making up the bit set. Split each 64 bit number into two more manageable 32 bit numbers. This generates a comma-separated list of C++-like unsigned long constants.
    • toStringOfWords

      public String toStringOfWords()
      Dump a comma-separated list of the words making up the bit set. This generates a comma-separated list of Java-like long int constants.
    • toStringWithRanges

      public String toStringWithRanges()
    • wordNumber

      private static int wordNumber(int bit)