You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Manipulation methods are mutable and chainable by design.
88
+
That is, for example, when you call `append(5)`, it will change
89
+
the internal representation and return the modified self,
90
+
rather than returning a new instance.
91
+
To get the copy of the instance, use `clone()`, or alternatively the copy constructor (`var copy = new MultiRange(orig)`).
92
+
93
+
-`new MultiRange(data?: Initializer)` Creates a new MultiRange object.
94
+
-`clone(): MultiRange` Clones this instance.
95
+
-`append(value: Initializer): MultiRange` Appends to this instance.
96
+
-`appendRange(min: number, max: number): MultiRange` Appends one range specified by the two parameters.
97
+
-`subtract(value: Initializer): MultiRange` Subtracts from this instance.
98
+
-`subtractRange(min: number, max: number): MultiRange` Subtracts one range specified by the two parameters.
99
+
-`intersect(value: Initializer): MultiRange` Remove integers which are not included in `value` (aka intersection).
100
+
-`has(value: Initializer): boolean` Checks if the instance contains the specified value.
101
+
-`hasRange(min: number, max: number): boolean` Checks if the instance contains the range specified by the two parameters.
102
+
-`isContinuous(): boolean` Checks if the current instance is continuous. Note that this returns false if the current range is empty.
103
+
-`length(): number` Calculates how many numbers are effectively included in this instance. (`multirange('1-10,51-60,90').length()` returns 21)
104
+
-`equals(cmp: Initializer): boolean` Checks if two MultiRange data are identical.
105
+
-`toString(): string` Returns the string respresentation of this MultiRange.
106
+
-`getRanges(): [number, number][]` Exports the whole range data as an array of [number, number] arrays.
107
+
-`toArray(): number[]` Builds an array of integer which holds all integers in this MultiRange. Note that this may be slow and memory-consuming for large ranges such as '1-10000'.
108
+
-`getIterator(): Object` Returns ES6-compatible iterator. See the description below.
124
109
125
110
### Iteration
126
111
@@ -163,6 +148,8 @@ npm test
163
148
164
149
Report any bugs and suggestions using GitHub issues.
165
150
151
+
**Performance Considerations**: This library works efficiently for large ranges as long as they're *mostly* continuous (e.g., `1-10240000,20480000-50960000`). However, this library is not intended to be efficient with a heavily fragmentated set of integers which are scarcely continuous (for example, random 10000 integers between 1 to 1000000).
0 commit comments