Package org.antlr.misc
Class BitSet
- java.lang.Object
-
- org.antlr.misc.BitSet
-
- All Implemented Interfaces:
java.lang.Cloneable,IntSet
public class BitSet extends java.lang.Object implements IntSet, java.lang.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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int el)or this element into this set (grow as necessary to accommodate)voidaddAll(int[] elements)voidaddAll(java.lang.Iterable<java.lang.Integer> elements)voidaddAll(IntSet set)Add all elements from incoming set to this set.IntSetand(IntSet a)Return the intersection of this set with the argument, creating a new set.voidandInPlace(BitSet a)private static longbitMask(int bitNumber)voidclear()voidclear(int el)java.lang.Objectclone()IntSetcomplement()IntSetcomplement(IntSet set)booleanequals(java.lang.Object other)intgetSingleElement()Get the first element you find and return it.voidgrowToInclude(int bit)Grows the set to a larger number of bits.booleanisNil()intlengthInLongWords()return how much space is being used by the bits array not how many actually have member bits on.booleanmember(int el)voidnotInPlace()voidnotInPlace(int maxBit)complement bits in the range 0..maxBit.voidnotInPlace(int minBit, int maxBit)complement bits in the range minBit..maxBit.intnumBits()private intnumWordsToHold(int el)static BitSetof(int el)static BitSetof(java.util.Collection<? extends java.lang.Integer> elements)static BitSetof(java.util.Map<? extends java.lang.Integer,?> elements)static BitSetof(IntSet set)IntSetor(IntSet a)return this | a in a new setvoidorInPlace(BitSet a)static BitSetrange(int a, int b)voidremove(int el)remove this element from this setprivate voidsetSize(int nwords)Sets the size of a set.intsize()Return the size of this set (not the underlying implementation's allocated memory size, for example).booleansubset(BitSet a)Is this contained within a?IntSetsubtract(IntSet a)voidsubtractInPlace(BitSet a)Subtract the elements of 'a' from 'this' in-place.int[]toArray()java.util.List<java.lang.Integer>toList()long[]toPackedArray()java.lang.StringtoString()java.lang.StringtoString(java.lang.String separator, java.util.List<java.lang.String> vocabulary)Create a string representation where instead of integer elements, the ith element of vocabulary is displayed instead.java.lang.StringtoString(Grammar g)Transform a bit set into a string by formatting each element as an integer separator The string to put in between elementsjava.lang.StringtoStringOfHalfWords()Dump a comma-separated list of the words making up the bit set.java.lang.StringtoStringOfWords()Dump a comma-separated list of the words making up the bit set.java.lang.StringtoStringWithRanges()private static intwordNumber(int bit)
-
-
-
Field Detail
-
BITS
protected static final int BITS
- See Also:
- Constant Field Values
-
LOG_BITS
protected static final int LOG_BITS
- See Also:
- Constant Field Values
-
MOD_MASK
protected static final int MOD_MASK
- See Also:
- Constant Field Values
-
bits
protected long[] bits
The actual data bits
-
-
Method Detail
-
add
public void add(int el)
or this element into this set (grow as necessary to accommodate)
-
addAll
public void addAll(IntSet set)
Description copied from interface:IntSetAdd all elements from incoming set to this set. Can limit to set of its own type.
-
addAll
public void addAll(int[] elements)
-
addAll
public void addAll(java.lang.Iterable<java.lang.Integer> elements)
-
and
public IntSet and(IntSet a)
Description copied from interface:IntSetReturn the intersection of this set with the argument, creating a new set.
-
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 java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
size
public int size()
Description copied from interface:IntSetReturn the size of this set (not the underlying implementation's allocated memory size, for example).
-
equals
public boolean equals(java.lang.Object other)
-
growToInclude
public void growToInclude(int bit)
Grows the set to a larger number of bits.- Parameters:
bit- element that must fit in set
-
getSingleElement
public int getSingleElement()
Get the first element you find and return it. Return Label.INVALID otherwise.- Specified by:
getSingleElementin interfaceIntSet
-
complement
public IntSet complement()
-
complement
public IntSet complement(IntSet set)
- Specified by:
complementin interfaceIntSet
-
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(java.util.Collection<? extends java.lang.Integer> elements)
-
of
public static BitSet of(java.util.Map<? extends java.lang.Integer,?> elements)
-
range
public static BitSet range(int a, int b)
-
orInPlace
public void orInPlace(BitSet a)
-
remove
public void remove(int el)
Description copied from interface:IntSetremove this element from this set
-
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'.
-
toArray
public int[] toArray()
-
toPackedArray
public long[] toPackedArray()
-
toString
public java.lang.String toString()
-
toString
public java.lang.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
-
toString
public java.lang.String toString(java.lang.String separator, java.util.List<java.lang.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 java.lang.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 java.lang.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 java.lang.String toStringWithRanges()
-
wordNumber
private static int wordNumber(int bit)
-
-