| java.lang.Object org.antlr.misc.IntervalSet
IntervalSet | public class IntervalSet implements IntSet(Code) | | A set of integers that relies on ranges being common to do
"run-length-encoded" like compression (if you view an IntSet like
a BitSet with runs of 0s and 1s). Only ranges are recorded so that
a few ints up near value 1000 don't cause massive bitsets, just two
integer intervals.
element values may be negative. Useful for sets of EPSILON and EOF.
0..9 char range is index pair ['\u0030','\u0039'].
Multiple ranges are encoded with multiple index pairs. Isolated
elements are encoded with an index pair where both intervals are the same.
The ranges are ordered and disjoint so that 2..6 appears before 101..103.
|
Field Summary | |
protected List | intervals The list of sorted, disjoint intervals. |
intervals | protected List intervals(Code) | | The list of sorted, disjoint intervals.
|
IntervalSet | public IntervalSet()(Code) | | Create a set with no elements
|
add | public void add(int el)(Code) | | Add a single element to the set. An isolated element is stored
as a range el..el.
|
add | public void add(int a, int b)(Code) | | Add interval; i.e., add all integers from a to b to set.
If b |
and | public IntSet and(IntSet other)(Code) | | Return a new set with the intersection of this set with other. Because
the intervals are sorted, we can use an iterator for each list and
just walk them together. This is roughly O(min(n,m)) for interval
list lengths n and m.
|
complement | public IntSet complement(int minElement, int maxElement)(Code) | | |
complement | public IntSet complement(IntSet vocabulary)(Code) | | Given the set of possible values (rather than, say UNICODE or MAXINT),
return a new set containing all elements in vocabulary, but not in
this. The computation is (vocabulary - this).
'this' is assumed to be either a subset or equal to vocabulary.
|
equals | public boolean equals(Object obj)(Code) | | Are two IntervalSets equal? Because all intervals are sorted
and disjoint, equals is a simple linear walk over both lists
to make sure they are the same. Interval.equals() is used
by the List.equals() method to check the ranges.
|
getIntervals | public List getIntervals()(Code) | | Return a list of Interval objects.
|
getMaxElement | public int getMaxElement()(Code) | | |
getMinElement | public int getMinElement()(Code) | | Return minimum element >= 0
|
getSingleElement | public int getSingleElement()(Code) | | If this set is a single integer, return it otherwise Label.INVALID
|
isNil | public boolean isNil()(Code) | | return true if this set has no members
|
member | public boolean member(int el)(Code) | | Is el in any range of this set?
|
of | public static IntervalSet of(int a, int b)(Code) | | Create a set with all ints within range [a..b] (inclusive)
|
remove | public void remove(int el)(Code) | | |
subtract | public IntSet subtract(IntSet other)(Code) | | Compute this-other via this&~other.
Return a new set containing all elements in this but not in other.
other is assumed to be a subset of this;
anything that is in other but not in this will be ignored.
|
toArray | public int[] toArray()(Code) | | |
|
|