Top Description Fields Constructors Methods
org.antlr.misc

public Class BitSet

extends Object
implements IntSet, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, org.antlr.misc.IntSet
Imports
org.antlr.analysis.Label, org.antlr.tool.Grammar, java.util.Collection, .Iterator, .List, .Map

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

Field Summary

Modifier and TypeField and Description
protected static final int
protected long[]
bits

The actual data bits

protected static final int
protected static final int

Constructor Summary

AccessConstructor and Description
public
BitSet()

Construct a bitset of size one word (64 bits)

public
BitSet(long[] bits_)

Construction from a static array of longs

public
BitSet(int
The size of the bitset in bits
nbits
)

Construct a bitset given the size

Method Summary

Modifier and TypeMethod and Description
public void
add(int el)

Implements org.antlr.misc.IntSet.add.

or this element into this set (grow as necessary to accommodate)
public void
addAll(IntSet set)

Implements org.antlr.misc.IntSet.addAll.

Add all elements from incoming set to this set.
public void
addAll(int[] elements)

public void
addAll(Iterable<Integer> elements)

public IntSet
and(IntSet a)

Implements org.antlr.misc.IntSet.and.

Return the intersection of this set with the argument, creating a new set.
public void
private static long
bitMask(int bitNumber)

public void
public void
clear(int el)

public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public IntSet
public IntSet
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Implements org.antlr.misc.IntSet.equals.

Indicates whether some other object is "equal to" this one.
public int
getSingleElement()

Implements org.antlr.misc.IntSet.getSingleElement.

Get the first element you find and return it.
public void
growToInclude(int
element that must fit in set
bit
)

Grows the set to a larger number of bits.

public boolean
public int
lengthInLongWords()

return how much space is being used by the bits array not how many actually have member bits on.

public boolean
public void
public void
notInPlace(int maxBit)

complement bits in the range 0..maxBit.

public void
notInPlace(int minBit, int maxBit)

complement bits in the range minBit..maxBit.

public int
private int
public static BitSet
of(int el)

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

public static BitSet
of(IntSet set)

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

public IntSet
or(IntSet a)

Implements org.antlr.misc.IntSet.or.

return this | a in a new set
public void
public static BitSet
range(int a, int b)

public void
remove(int el)

Implements org.antlr.misc.IntSet.remove.

remove this element from this set
private void
setSize(int
how many words the new set should be
nwords
)

Sets the size of a set.

public int
size()

Implements org.antlr.misc.IntSet.size.

Return the size of this set (not the underlying implementation's allocated memory size, for example).
public boolean
subset(BitSet a)

Is this contained within a?

public IntSet
public void
subtractInPlace(BitSet a)

Subtract the elements of 'a' from 'this' in-place.

public int[]
public List<Integer>
public long[]
public String
toString()

Overrides java.lang.Object.toString.

Implements org.antlr.misc.IntSet.toString.

Returns a string representation of the object.
public String

Returns:

A commma-separated list of values
toString
(Grammar g)

Implements org.antlr.misc.IntSet.toString.

Transform a bit set into a string by formatting each element as an integer separator The string to put in between elements
public String

Returns:

A commma-separated list of character constants.
toString
(String separator, List<String> vocabulary)

Create a string representation where instead of integer elements, the ith element of vocabulary is displayed instead.

public String
toStringOfHalfWords()

Dump a comma-separated list of the words making up the bit set.

public String
toStringOfWords()

Dump a comma-separated list of the words making up the bit set.

public String
private static int
wordNumber(int bit)

Inherited from java.lang.Object:
finalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

BITSback to summary
protected static final int BITS
bitsback to summary
protected long[] bits

The actual data bits

LOG_BITSback to summary
protected static final int LOG_BITS
MOD_MASKback to summary
protected static final int MOD_MASK

Constructor Detail

BitSetback to summary
public BitSet()

Construct a bitset of size one word (64 bits)

BitSetback to summary
public BitSet(long[] bits_)

Construction from a static array of longs

BitSetback to summary
public BitSet(int nbits)

Construct a bitset given the size

Parameters
nbits:int

The size of the bitset in bits

Method Detail

addback to summary
public void add(int el)

Implements org.antlr.misc.IntSet.add.

or this element into this set (grow as necessary to accommodate)

Annotations
@Override
addAllback to summary
public void addAll(IntSet set)

Implements org.antlr.misc.IntSet.addAll.

Doc from org.antlr.misc.IntSet.addAll.

Add all elements from incoming set to this set. Can limit to set of its own type.

Annotations
@Override
addAllback to summary
public void addAll(int[] elements)
addAllback to summary
public void addAll(Iterable<Integer> elements)
andback to summary
public IntSet and(IntSet a)

Implements org.antlr.misc.IntSet.and.

Doc from org.antlr.misc.IntSet.and.

Return the intersection of this set with the argument, creating a new set.

Annotations
@Override
andInPlaceback to summary
public void andInPlace(BitSet a)
bitMaskback to summary
private static long bitMask(int bitNumber)
clearback to summary
public void clear()
clearback to summary
public void clear(int el)
cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a clone of this instance.

Annotations
@Override
complementback to summary
public IntSet complement()
complementback to summary
public IntSet complement(IntSet set)

Implements org.antlr.misc.IntSet.complement.

Annotations
@Override
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Implements org.antlr.misc.IntSet.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getSingleElementback to summary
public int getSingleElement()

Implements org.antlr.misc.IntSet.getSingleElement.

Get the first element you find and return it. Return Label.INVALID otherwise.

Annotations
@Override
growToIncludeback to summary
public void growToInclude(int bit)

Grows the set to a larger number of bits.

Parameters
bit:int

element that must fit in set

isNilback to summary
public boolean isNil()

Implements org.antlr.misc.IntSet.isNil.

Annotations
@Override
lengthInLongWordsback to summary
public int lengthInLongWords()

return how much space is being used by the bits array not how many actually have member bits on.

memberback to summary
public boolean member(int el)

Implements org.antlr.misc.IntSet.member.

Annotations
@Override
notInPlaceback to summary
public void notInPlace()
notInPlaceback to summary
public void notInPlace(int maxBit)

complement bits in the range 0..maxBit.

notInPlaceback to summary
public void notInPlace(int minBit, int maxBit)

complement bits in the range minBit..maxBit.

numBitsback to summary
public int numBits()
numWordsToHoldback to summary
private int numWordsToHold(int el)
ofback to summary
public static BitSet of(int el)
ofback to summary
public static BitSet of(Collection<? extends Integer> elements)
ofback to summary
public static BitSet of(IntSet set)
ofback to summary
public static BitSet of(Map<? extends Integer, ?> elements)
orback to summary
public IntSet or(IntSet a)

Implements org.antlr.misc.IntSet.or.

return this | a in a new set

Annotations
@Override
orInPlaceback to summary
public void orInPlace(BitSet a)
rangeback to summary
public static BitSet range(int a, int b)
removeback to summary
public void remove(int el)

Implements org.antlr.misc.IntSet.remove.

Doc from org.antlr.misc.IntSet.remove.

remove this element from this set

Annotations
@Override
setSizeback to summary
private void setSize(int nwords)

Sets the size of a set.

Parameters
nwords:int

how many words the new set should be

sizeback to summary
public int size()

Implements org.antlr.misc.IntSet.size.

Doc from org.antlr.misc.IntSet.size.

Return the size of this set (not the underlying implementation's allocated memory size, for example).

Annotations
@Override
subsetback to summary
public boolean subset(BitSet a)

Is this contained within a?

subtractback to summary
public IntSet subtract(IntSet a)

Implements org.antlr.misc.IntSet.subtract.

Annotations
@Override
subtractInPlaceback to summary
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'.

toArrayback to summary
public int[] toArray()
toListback to summary
public List<Integer> toList()

Implements org.antlr.misc.IntSet.toList.

Annotations
@Override
toPackedArrayback to summary
public long[] toPackedArray()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements org.antlr.misc.IntSet.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
toStringback to summary
public String toString(Grammar g)

Implements org.antlr.misc.IntSet.toString.

Transform a bit set into a string by formatting each element as an integer separator The string to put in between elements

Returns:String

A commma-separated list of values

Annotations
@Override
toStringback to summary
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:String

A commma-separated list of character constants.

toStringOfHalfWordsback to summary
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.

toStringOfWordsback to summary
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.

toStringWithRangesback to summary
public String toStringWithRanges()
wordNumberback to summary
private static int wordNumber(int bit)