Constructor
new RangeGroup(ranges, optionsnullable)
Create a new RangeGroup
| Name | Type | Attributes | Description |
|---|---|---|---|
ranges | RangeGroup~Definition | Initial set of ranges for this group | |
options | RangeGroup~CreateOptions | <nullable> | Options for creation |
- Source
Members
ranges :Array.<Range>
Internal list of ranges
- Array.<Range>
- Source
type :RangeType
Range type to use for this group
- Source
(static) default_type :RangeType
Default type to be used if none is provided in the constructor of RangeGroup
- Source
Methods
@@iterator()
Iterator interface, allowing use with things like for-of loops or Array.from. To customize how the values are iterated, pass arguments to RangeGroup#iterate instead.
- Source
add()
An alias for RangeGroup#union
- Source
cardinality()
An alias for RangeGroup#size
- Source
clear() → {RangeGroup}
Remove all elements from this group
- Source
modified this
- Type:
- RangeGroup
contains()
An alias for RangeGroup#has
- Source
copy() → {RangeGroup}
Make a deep copy of this range group. This calls RangeType.copy internally.
- Source
- Type:
- RangeGroup
delete()
An alias for RangeGroup#difference
- Source
diff(other, optionsnullable) → {RangeGroup|boolean}
Compute the differences between this and another RangeGroup. For diff results, this and other are referred to as a and b respectively. There are three different operations, denoted a, b, and ab. They can be understood as:
- a: values present in
abut notb; set difference "a - b"; deletions fromother - b: values present in
bbut nota; set difference "b - a"; insertions intoother - ab: values present in both
aandb; set intersection "a ∩ b"
Filtering by the various diff operations can give you set operations like union, intersection, difference, and symmetric difference (see filter param). This method is used to implement nearly all the other operations on RangeGroup.
The default options will compute set operations. For a more traditional "diff" behavior, use options: {copy:true, track_sources:true, self_union:false}. This gives you the full differences between the two groups, telling you which parts came from a or b. You can reuse this result multiple times to get set operations, simply by filterering for Range#a and/or Range#b. See RangeGroup#filter and its variants, or the filter option of RangeGroup#selfUnion adn its variants.
| Name | Type | Attributes | Description |
|---|---|---|---|
other | RangeGroup | | The group to diff against | |
options | RangeGroup~DiffOptions | <nullable> | Options to customize the diff behavior |
- Source
Contains the diff result range group, which may equal this if copy was false. If bool was true, a boolean value is instead returned indicating whether that range group would have been non-empty.
- Type:
- RangeGroup |
boolean
difference(other) → {RangeGroup}
Compute the in-place set difference between this and other: a - b. This uses RangeGroup#diff internally
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
modified this
- Type:
- RangeGroup
filter(predicate) → {RangeGroup}
Filter the ranges. You might use this to filter by Range#a or Range#b nullity, as returned by RangeGroup#diff
| Name | Type | Description |
|---|---|---|
predicate | RangeGroup~Filter |
- Source
modified this
- Type:
- RangeGroup
has(…args) → {boolean}
Test whether an element is contained in this group. This uses RangeGroup#search internally, returning the has result.
| Name | Type | Attributes | Description |
|---|---|---|---|
args | any | <repeatable> | arguments are the same as RangeGroup#search |
- Source
- Type:
- boolean
hasDifference(other) → {boolean}
Check if this has values not present in other: a - b. This uses RangeGroup#diff internally
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
- Type:
- boolean
hasFilter(predicate) → {boolean}
Check if any range matches the filter predicate
| Name | Type | Description |
|---|---|---|
predicate | RangeGroup~Filter |
- Source
- Type:
- boolean
hasIntersection(other) → {boolean}
Check if this intersects with other: a ∩ b. This uses RangeGroup#diff internally
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
- Type:
- boolean
hasSelfUnion(filternullable) → {boolean}
Check if any ranges would remain after calling RangeGroup#selfUnion. This is as though the bool option were set to true
| Name | Type | Attributes | Description |
|---|---|---|---|
filter | RangeGroup~Filter | <nullable> | optional filter param, which is the same as the filter that can be passed to RangeGroup#selfUnion |
- Source
- Type:
- boolean
hasSymmetricDifference(other) → {boolean}
Check if this has values not present in other: a - b. This uses RangeGroup#diff internally
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
- Type:
- boolean
hasUnion(other) → {boolean}
Check if a union of this and other would be non-empty: a ∪ b.
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
- Type:
- boolean
intersect(other) → {RangeGroup}
Compute the in-place set intersection between this and other: a ∩ b. This uses RangeGroup#diff internally
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
modified this
- Type:
- RangeGroup
isEmpty() → {boolean}
Check if this range group is empty, meaning there are no elements: a = ∅
- Source
true if empty
- Type:
- boolean
isEqual(other) → {boolean}
Check if this and other range groups are equal, meaning they have identical elements: a = b. This uses RangeGroup#hasSymmetricDifference internally, returning its negated value
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
true if equal
- Type:
- boolean
isProperSubset(other) → {boolean}
Check whether this is a proper/strict subset of other, meaning all of its elements are in other, but does not have all the elements of other: a ⊂ b. This uses two calls to RangeGroup#hasDifference internally
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
true if a proper/strict subset
- Type:
- boolean
isProperSuperset(other) → {boolean}
Check whether this is a proper/strict superset of other, meaning all other elements are also in this: a ⊃ b. This is equivalent to other.isProperSubset(this)
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
true if a proper/strict superset
- Type:
- boolean
isStrictSubset()
An alias for RangeGroup#isProperSubset
- Source
isStrictSuperset()
An alias for RangeGroup#isProperSuperset
- Source
isSubset(other) → {boolean}
Check whether this is a subset of other, meaning all of its elements are also in other: a ⊆ b. This uses RangeGroup#hasDifference internally, returning its negated value
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
true if a subset
- Type:
- boolean
isSuperset(other) → {boolean}
Check whether this is a superset of other, meaning all other elements are also in this: a ⊇ b. This is equivalent to other.isSubset(this)
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
true if a superset
- Type:
- boolean
(generator) iterate(reversenullable, …args) → {any}
Generator for values within the range group. This calls RangeType.iterate internally.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
reverse | boolean | <nullable> | false | iterate ranges forward or backward; forward indicates the first value will give a negative comparison against any subsequent values |
args | any | <repeatable> | arguments to forward to the RangeType's iterator |
- Source
values from the range
- Type:
- any
normalize() → {RangeGroup}
Puts the range group into a normalized form, where ranges are sorted and self intersections have been removed. This calls RangeGroup#sort and RangeGroup#selfUnion
- Source
modified this
- Type:
- RangeGroup
search(element, optionsnullable) → {RangeGroup~SearchResult}
Find the position in RangeGroup#ranges where element could be inserted to maintain a sorted array. If the element belongs to a range already, then the index to that range would be returned, with has flag set. In other words, the index is the lower bound: the first position that does not come before element.
The search output provides useful comparison information that was used to find the location. For a simple boolean output, you may wish to use RangeGroup#has instead.
| Name | Type | Attributes | Description |
|---|---|---|---|
element | any | the element to search for | |
options | RangeGroup~SearchOptions | <nullable> | customizes the options |
- Source
- Type:
- RangeGroup~SearchResult
selfUnion(options) → {RangeGroup|boolean}
Union of individual ranges within this range group (e.g. remove self-intersections). This will remove empty ranges, where the start is after (and not equal) the end.
| Name | Type | Description |
|---|---|---|
options | RangeGroup~SelfUnionOptions | alters the self union behavior to accomodate a few different, common operations |
- Source
By default, modified this. If copy flag was set, it will return a modified copy instead. If bool flag was set, it will return true/false, whether the result would have been non-empty
- Type:
- RangeGroup |
boolean
size() → {number}
Get the total number of elements held by this group. This dynamically sums up the size of each range in the group, so it is not a constant-time operation. This calls RangeType.size internally.
If you wish to see how many contiguous ranges there are, get the length of RangeGroup#ranges instead.
- Source
- Type:
- number
sort() → {RangeGroup}
Performs an in-place sort of ranges in the group. Ranges are ordered by their start
- Source
modified this
- Type:
- RangeGroup
subtract()
An alias for RangeGroup#difference
- Source
symmetricDifference(other) → {RangeGroup}
Compute the in-place set symmetric difference between this and other: a Δ b. This uses RangeGroup#diff internally
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
modified this
- Type:
- RangeGroup
toCleared() → {RangeGroup}
Same as RangeGroup#clear, but returns a copy that is cleared. This is functionally equivalent to creating a new range group with the same type
- Source
- Type:
- RangeGroup
toDifferenced(other) → {RangeGroup}
Same as RangeGroup#difference, but returning a copy instead of modifying the range group in-place
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
new group containing the difference
- Type:
- RangeGroup
toFiltered(predicate) → {RangeGroup}
Same as RangeGroup#filter, but returns a copy instead
| Name | Type | Description |
|---|---|---|
predicate | RangeGroup~Filter |
- Source
a filtered copy
- Type:
- RangeGroup
toIntersected(other) → {RangeGroup}
Same as RangeGroup#intersect, but returning a copy instead of modifying the range group in-place
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
new group containing the intersection
- Type:
- RangeGroup
toSelfUnioned(filternullable)
Same as RangeGroup#selfUnion, but returns a copy instead. This is as though the copy option were set to true
| Name | Type | Attributes | Description |
|---|---|---|---|
filter | RangeGroup~Filter | <nullable> | optional filter param, which is the same as the filter that can be passed to RangeGroup#selfUnion |
- Source
toSymmetricDifferenced(other) → {RangeGroup}
Same as RangeGroup#symmetricDifference, but returning a copy instead of modifying the range group in-place
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
new group containing the symmetric difference
- Type:
- RangeGroup
toUnioned(other) → {RangeGroup}
Same as RangeGroup#union, but returning a copy instead of modifying the range group in-place
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
new group containing the union
- Type:
- RangeGroup
union(other) → {RangeGroup}
Compute the in-place set union between this and other: a ∪ b. This uses RangeGroup#diff internally
| Name | Type | Description |
|---|---|---|
other | RangeGroup | |
- Source
modified this
- Type:
- RangeGroup
Type Definitions
CreateOptions
Options to pass to the constructor of RangeGroup
- object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
type | RangeType | <optional> <nullable> | null | Range type to be used with this group; if null, it uses RangeGroup.default_type |
normalize | boolean | <optional> | false | whether to call RangeGroup#normalize after construction |
- Source
Definition
Arguments defining a RangeGroup. A falsey value initializes an empty RangeGroup. Otherwise, this should be an array containing ranges for the group; each range can be a preconstructed Range or an array of arguments to construct one. Any Range will be reused, while the containing array is copied.
Caution: Since a Range will be reused, auto-normalizing types like IntNormType are going to assume the ranges are already normalized to be inclusive. You can pass arguments to construct a new Range to construct an auto-normalized range instead.
For convenience, you can also pass just a single preconstructed range. You can pass a single array of arguments to construct a range as well, but only if the first argument is not an object (as identified by typeof).
- any
- Source
DiffOptions
Options for calculating diff between two range groups. For use with RangeGroup#diff
- object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
filter | object.<string, boolean> | | <optional> | false | Specifies what diff operations you want to include in the results. Indicate which parts, Setting this to a falsey value (the default) will return all results, e.g. |
bool | boolean | <optional> | false | Just return true/false whether or not the filtered output would be non-empty; when |
copy | boolean | <optional> | true | If true, returns the diff results separately, rather than modifying |
track_sources | boolean | <optional> | false | In the diff output, track where the range came from with the keys Range#a and Range#b, with values equaling the index into |
self_union | boolean | <optional> | true | Merges adjacent ranges, in the same manner as RangeGroup#selfUnion, but using an inline calculation. Use this if you don't care about tracking the specific diff sources/operations, and just want to get the result of the set operationon output. The |
- Source
Filter(range) → {boolean}
Used for a few different methods to filter RangeGroup#ranges
| Name | Type | Description |
|---|---|---|
range | Range | the range to check whether it should be included |
- Source
whether the range should be included
- Type:
- boolean
SearchOptions
Options to customize search in RangeGroup#search
- object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
excl | boolean | <optional> | false | Whether |
end | boolean | <optional> | false | When |
first | number | <optional> | 0 | Inclusive lower bound into RangeGroup#ranges for the search. If less than zero, zero is used. |
last | number | <optional> | -1 | Inclusive upper bound into RangeGroup#ranges for the search. A negative value counts from the end, clamping to zero, e.g. |
- Source
SearchResult
Output of RangeGroup#search
- object
| Name | Type | Attributes | Description |
|---|---|---|---|
index | number | Lower bound index; e.g. the position where | |
has | boolean | Whether the range at | |
start | RangeType~CompareResult | <nullable> | Comparison with the Range#start from |
end | RangeType~CompareResult | <nullable> | Comparison with the bounding Range#end. Comparison is made with
|
- Source
SelfUnionOptions
Options to customize RangeGroup#selfUnion behavior.
- object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
filter | RangeGroup~Filter | <optional> | null | Filter function to apply to each range before unioning. This is useful for filtering by Range#a or Range#b nullity, as returned by RangeGroup#diff. |
bool | boolean | <optional> | false | If |
copy | boolean | <optional> | false | If |
- Source