The goog.math.RangeSet Class

goog.math.RangeSet()

Constructs a new RangeSet, which can store numeric ranges. Ranges are treated as half-closed: that is, they are exclusive of their end value [start, end). New ranges added to the set which overlap the values in one or more existing ranges will be merged.

.__iterator__(opt_keys)

Returns an iterator that iterates over the ranges in the RangeSet.

opt_keys {boolean=}
Ignored for RangeSets.
returns {!goog.iter.Iterator}
An iterator over the values in the set.

.add(a)

Adds a range to the set. If the new range overlaps existing values, those ranges will be merged.

a {goog.math.Range}
The range to add.

.clear()

Removes all values in the set.

.clone()

returns {!goog.math.RangeSet}
A new RangeSet containing the same values as this one.

.contains(a)

Determines whether a given range is in the set. Only succeeds if the entire range is available.

a {goog.math.Range}
The query range.
returns {boolean}
Whether the entire requested range is set.

.containsValue(value)

Determines whether a given value is set in the RangeSet.

value {number}
The value to test.
returns {boolean}
Whether the given value is in the set.

.coveredLength()

returns {number}
The sum of the lengths of ranges covered in the set.

.difference(set)

Subtracts the ranges of another set from this one, returning the result as a new RangeSet.

set {!goog.math.RangeSet}
The RangeSet to subtract.
returns {!goog.math.RangeSet}
A new RangeSet containing all values in this set minus the values of the input set.

.equals(a, b)

Compares two sets for equality.

a {goog.math.RangeSet}
A range set.
b {goog.math.RangeSet}
A range set.
returns {boolean}
Whether both sets contain the same values.

.getBounds()

returns {goog.math.Range}
The total range this set covers, ignoring any gaps between ranges.

.intersection(set)

Intersects this RangeSet with another.

set {goog.math.RangeSet}
The RangeSet to intersect with.
returns {!goog.math.RangeSet}
A new RangeSet containing all values set in both this and the input set.

.inverse(range)

Creates an inverted slice of this set over the input range.

range {goog.math.Range}
The range to copy into the slice.
returns {!goog.math.RangeSet}
A new RangeSet containing inverted values from the original over the input range.

.isEmpty()

returns {boolean}
Whether any ranges are currently in the set.

.remove(a)

Removes a range of values from the set.

a {goog.math.Range}
The range to remove.

.slice(range)

Creates a subset of this set over the input range.

range {goog.math.Range}
The range to copy into the slice.
returns {!goog.math.RangeSet}
A new RangeSet with a copy of the values in the input range.

.toString()

returns {string}
A debug string in the form [[1, 5], [8, 9], [15, 30]].

.union(set)

Returns the union of this RangeSet with another.

set {goog.math.RangeSet}
Another RangeSet.
returns {!goog.math.RangeSet}
A new RangeSet containing all values from either set.