Skip to content

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.

T

readonly T[]

Flat [start, end, …] pairs, ascending and disjoint.

readonly [T, T]

The inclusive window to report gaps within.

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.

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.

When intervals holds an odd number of bounds.