IntervalSet class

This class implements the IntervalSet backed by a sorted array of non-overlapping intervals. It is particularly efficient for representing large collections of numbers, where the majority of elements appear as part of a sequential range of numbers that are all part of the set. For example, the set { 1, 2, 3, 4, 7, 8 } may be represented as { 1, 4, 7, 8 }.

This class is able to represent sets containing any combination of values in the range {@link int#MIN_VALUE} to {@link int#MAX_VALUE} (inclusive).

Constructors

IntervalSet([List<Interval>? intervals])
IntervalSet.ofOne(int a)
Create a set with a single element, el. */
IntervalSet.ofSet(IntervalSet set)

Properties

hashCode int
The hash code for this object.
no setteroverride
intervals List<Interval>
The list of sorted, disjoint intervals. */
getter/setter pair
isNil bool
{@inheritDoc}
no setter
length int
no setter
maxElement int
Returns the maximum value contained in the set if not isNil().
no setter
minElement int
Returns the minimum value contained in the set if not isNil().
no setter
readonly bool
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(Interval addition) → void
addAll(IntervalSet? set) IntervalSet
addOne(int el) → void
Add a single element to the set. An isolated element is stored as a range el..el.
addRange(int a, int b) → void
Add interval; i.e., add all integers from a to b to set. If b<a, do nothing. Keep list in sorted order (by left range value). If overlap, combine ranges. For example, If this is {1..5, 10..20}, adding 6..7 yields {1..5, 6..7, 10..20}. Adding 4..8 yields {1..8, 10..20}.
clear() → void
complement(IntervalSet? vocabulary) IntervalSet?
{@inheritDoc} */
complementRange(int minElement, int maxElement) IntervalSet?
contains(int el) bool
{@inheritDoc} */
elementName(Vocabulary vocabulary, int a) String
get(int i) int
Get the ith element of ordered set. Used only by RandomPhrase so don't bother to implement if you're not doing that for a new ANTLR code gen target.
isReadonly() bool
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(int el) → void
setReadonly(bool readonly) → void
toIntegerList() List<int>
toList() List<int>
toSet() Set<int>
toString({bool elemAreChar = false, Vocabulary? vocabulary}) String
A string representation of this object.
override

Operators

operator +(IntervalSet other) IntervalSet
{@inheritDoc} */
operator -(IntervalSet a) IntervalSet
operator ==(Object obj) bool
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.
override
operator |(IntervalSet a) IntervalSet

Static Properties

COMPLETE_CHAR_SET IntervalSet
final
EMPTY_SET IntervalSet
final

Static Methods

ofRange(int a, int b) IntervalSet
Create a set with all ints within range a..b (inclusive) */
or(List<IntervalSet> sets) IntervalSet
combine all sets in the array returned the or'd value */
subtract(IntervalSet left, IntervalSet right) IntervalSet
Compute the set difference between two interval sets. The specific operation is {@code left - right}. If either of the input sets is null, it is treated as though it was an empty set.