complementIntervals
complementIntervals<
T>(intervals,bounds,compare,step):T[]
Defined in: interval/complement-intervals.ts:30
The gaps: every point of bounds that none of intervals covers, as the
same flat, stride-2 [start, end, …] form.
Free slots between the meetings in a calendar, the lines a coverage report
never reached, the holes in an allocation map. Anything outside bounds is
ignored rather than reported, since “everything not covered” has no answer
over an unbounded domain.
intervals must already be ascending and disjoint — run mergeIntervals
first if it is not. Its bounds may lie outside bounds; the parts that do
are clipped.
Complexity: O(n) in the interval count, O(n) extra space.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”intervals
Section titled “intervals”readonly T[]
Flat [start, end, …] pairs, ascending and disjoint.
bounds
Section titled “bounds”readonly [T, T]
The inclusive window to report gaps within.
compare
Section titled “compare”Comparator<T>
Total order over the bound type.
IntervalStep<T>
Successor and predecessor; the gap beside [3, 5] ends at 2
and resumes at 6, and only step knows that.
Returns
Section titled “Returns”T[]
A fresh flat array, ascending, disjoint, and covering exactly
bounds minus intervals. Empty when intervals covers all of bounds
or when bounds is itself empty.
Throws
Section titled “Throws”When intervals holds an odd number of bounds.