Package org.antlr.misc
Class BitSet
java.lang.Object
org.antlr.misc.BitSet
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int el) or this element into this set (grow as necessary to accommodate)void
addAll
(int[] elements) void
void
Add all elements from incoming set to this set.Return the intersection of this set with the argument, creating a new set.void
andInPlace
(BitSet a) private static final long
bitMask
(int bitNumber) void
clear()
void
clear
(int el) clone()
complement
(IntSet set) boolean
int
Get the first element you find and return it.void
growToInclude
(int bit) Grows the set to a larger number of bits.boolean
isNil()
int
return how much space is being used by the bits array not how many actually have member bits on.boolean
member
(int el) void
void
notInPlace
(int maxBit) complement bits in the range 0..maxBit.void
notInPlace
(int minBit, int maxBit) complement bits in the range minBit..maxBit.int
numBits()
private final int
numWordsToHold
(int el) static BitSet
of
(int el) static BitSet
of
(Collection elements) static BitSet
static BitSet
return this | a in a new setvoid
static BitSet
range
(int a, int b) void
remove
(int el) remove this element from this setprivate void
setSize
(int nwords) Sets the size of a set.int
size()
Return the size of this set (not the underlying implementation's allocated memory size, for example).boolean
Is this contained within a?void
Subtract the elements of 'a' from 'this' in-place.int[]
toArray()
toList()
long[]
toString()
Create a string representation where instead of integer elements, the ith element of vocabulary is displayed instead.Transform a bit set into a string by formatting each element as an integer separator The string to put in between elementsDump a comma-separated list of the words making up the bit set.Dump a comma-separated list of the words making up the bit set.private static final int
wordNumber
(int bit)
-
Field Details
-
BITS
protected static final int BITS- See Also:
-
LOG_BITS
protected static final int LOG_BITS- See Also:
-
MOD_MASK
protected static final int MOD_MASK- See Also:
-
bits
protected long[] bitsThe actual data bits
-
-
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) -
addAll
Description copied from interface:IntSet
Add all elements from incoming set to this set. Can limit to set of its own type. -
addAll
public void addAll(int[] elements) -
addAll
-
and
Description copied from interface:IntSet
Return the intersection of this set with the argument, creating a new set. -
andInPlace
-
bitMask
private static final long bitMask(int bitNumber) -
clear
public void clear() -
clear
public void clear(int el) -
clone
-
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). -
equals
-
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) -
getSingleElement
public int getSingleElement()Get the first element you find and return it. Return Label.INVALID otherwise.- Specified by:
getSingleElement
in interfaceIntSet
-
isNil
public boolean isNil() -
complement
-
complement
- Specified by:
complement
in 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 final int numWordsToHold(int el) -
of
-
of
-
of
-
of
-
range
-
or
return this | a in a new set -
orInPlace
-
remove
public void remove(int el) Description copied from interface:IntSet
remove 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
Is this contained within a? -
subtractInPlace
Subtract the elements of 'a' from 'this' in-place. Basically, just turn off all bits of 'this' that are in 'a'. -
subtract
-
toList
-
toArray
public int[] toArray() -
toPackedArray
public long[] toPackedArray() -
toString
-
toString
Transform a bit set into a string by formatting each element as an integer separator The string to put in between elements -
toString
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
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
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
-
wordNumber
private static final int wordNumber(int bit)
-