|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.antlr.misc.IntervalSet
public class IntervalSet
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 ['0','9']. 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 java.util.List |
intervals
The list of sorted, disjoint intervals. |
Constructor Summary | |
---|---|
IntervalSet()
Create a set with no elements |
Method Summary | |
---|---|
void |
add(int el)
Add a single element to the set. |
protected void |
add(Interval addition)
|
void |
add(int a,
int b)
Add interval; i.e., add all integers from a to b to set. |
void |
addAll(IntSet set)
Add all elements from incoming set to this set. |
IntSet |
and(IntSet other)
Return a new set with the intersection of this set with other. |
IntSet |
complement(int minElement,
int maxElement)
|
IntSet |
complement(IntSet vocabulary)
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. |
boolean |
equals(java.lang.Object obj)
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. |
java.util.List |
getIntervals()
Return a list of Interval objects. |
int |
getMaxElement()
|
int |
getMinElement()
Return minimum element >= 0 |
int |
getSingleElement()
If this set is a single integer, return it otherwise Label.INVALID |
boolean |
isNil()
return true if this set has no members |
boolean |
member(int el)
Is el in any range of this set? |
static IntervalSet |
of(int a)
Create a set with a single element, el. |
static IntervalSet |
of(int a,
int b)
Create a set with all ints within range [a..b] (inclusive) |
IntSet |
or(IntSet a)
TODO: implement this! |
void |
remove(int el)
remove this element from this set |
int |
size()
Return the size of this set (not the underlying implementation's allocated memory size, for example). |
IntSet |
subtract(IntSet other)
Compute this-other via this&~other. |
int[] |
toArray()
|
java.util.List |
toList()
|
org.antlr.runtime.BitSet |
toRuntimeBitSet()
|
java.lang.String |
toString()
|
java.lang.String |
toString(Grammar g)
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.List intervals
Constructor Detail |
---|
public IntervalSet()
Method Detail |
---|
public static IntervalSet of(int a)
public static IntervalSet of(int a, int b)
public void add(int el)
add
in interface IntSet
public void add(int a, int b)
protected void add(Interval addition)
public void addAll(IntSet set)
IntSet
addAll
in interface IntSet
public IntSet complement(int minElement, int maxElement)
public IntSet complement(IntSet vocabulary)
complement
in interface IntSet
public IntSet subtract(IntSet other)
subtract
in interface IntSet
public IntSet or(IntSet a)
or
in interface IntSet
public IntSet and(IntSet other)
and
in interface IntSet
public boolean member(int el)
member
in interface IntSet
public boolean isNil()
isNil
in interface IntSet
public int getSingleElement()
getSingleElement
in interface IntSet
public int getMaxElement()
public int getMinElement()
public java.util.List getIntervals()
public boolean equals(java.lang.Object obj)
equals
in interface IntSet
equals
in class java.lang.Object
public java.lang.String toString()
toString
in interface IntSet
toString
in class java.lang.Object
public java.lang.String toString(Grammar g)
toString
in interface IntSet
public int size()
IntSet
size
in interface IntSet
public java.util.List toList()
toList
in interface IntSet
public int[] toArray()
public org.antlr.runtime.BitSet toRuntimeBitSet()
public void remove(int el)
IntSet
remove
in interface IntSet
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |