Package antlr.collections.impl
Class BitSet
java.lang.Object
antlr.collections.impl.BitSet
- All Implemented Interfaces:
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.
- Author:
- Terence Parr,
Pete Wells
-
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
andInPlace
(BitSet a) void
clear()
void
clear
(int el) clone()
int
degree()
boolean
code "inherited" from java.util.BitSetstatic Vector
getRanges
(int[] elems) Find ranges in a set element array.void
growToInclude
(int bit) Grows the set to a larger number of bits.int
return how much space is being used by the bits array not how many actually have member bits on.boolean
member
(int el) boolean
nil()
not()
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.static BitSet
of
(int el) return this | a in a new setvoid
void
remove
(int el) int
size()
boolean
Is this contained within a?void
Subtract the elements of 'a' from 'this' in-place.int[]
toArray()
long[]
toString()
Transform a bit set into a string by formatting each element as an integertoString
(String separator, CharFormatter formatter) Transform a bit set into a string of characters.Create a string representation where instead of integer elements, the ith element of vocabulary is displayed instead.Dump 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.toStringWithRanges
(String separator, CharFormatter formatter) Print out the bit set but collapse char ranges.
-
Field Details
-
BITS
protected static final int BITS- See Also:
-
NIBBLE
protected static final int NIBBLE- 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) -
and
-
andInPlace
-
clear
public void clear() -
clear
public void clear(int el) -
clone
-
degree
public int degree() -
equals
code "inherited" from java.util.BitSet -
getRanges
Find ranges in a set element array. @param elems The array of elements representing the set, usually from Bit Set.toArray().- Returns:
- Vector of ranges.
-
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) -
nil
public boolean nil() -
not
-
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. -
of
-
or
return this | a in a new set -
orInPlace
-
remove
public void remove(int el) -
size
public int size() -
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'. -
toArray
public int[] toArray() -
toPackedArray
public long[] toPackedArray() -
toString
-
toString
Transform a bit set into a string by formatting each element as an integer- Returns:
- A commma-separated list of values
-
toString
Transform a bit set into a string of characters.- Parameters:
formatter
- An object implementing the CharFormatter interface.- Returns:
- A commma-separated list of character constants.
-
toString
Create a string representation where instead of integer elements, the ith element of vocabulary is displayed instead. Vocabulary is a Vector of Strings.- 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
Print out the bit set but collapse char ranges.
-