Skip to content

intersectIntervals

intersectIntervals<T>(a, b, compare): T[]

Defined in: interval/intersect-intervals.ts:21

Every point both sets cover, as the same flat, stride-2 [start, end, …] form.

Both inputs must already be ascending and disjoint — run mergeIntervals first if they are not. Needs no IntervalStep, unlike complementIntervals and subtractIntervals: an intersection’s bounds are always bounds one of the inputs already named, so nothing has to be stepped past.

Complexity: O(n + m) in the two interval counts, by a single merge walk.

T

readonly T[]

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

readonly T[]

The same, and independent of a’s bounds.

Comparator<T>

Total order over the bound type.

T[]

A fresh flat array, ascending and disjoint. Inherits both inputs’ non-adjacency: it can only narrow intervals, never bring two closer.

When either input holds an odd number of bounds.