Skip to content

subtractIntervals

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

Defined in: interval/subtract-intervals.ts:29

What remains of a once every point of b is removed, as the same flat, stride-2 [start, end, …] form.

How a firewall carves an exception out of an allowlist: exact in both directions, so no point of b survives and no point of a is lost.

Both inputs must already be ascending and disjoint — run mergeIntervals first if they are not.

Complexity: O(n + m) amortised in the two interval counts. Each hole is revisited only while it still overlaps the interval under consideration, and a hole that ends before the current interval starts is retired for good.

T

readonly T[]

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

readonly T[]

The holes to remove, ascending and disjoint.

Comparator<T>

Total order over the bound type.

IntervalStep<T>

Successor and predecessor; removing [3, 5] leaves a piece ending at 2 and one resuming at 6, and only step knows those.

T[]

A fresh flat array, ascending and disjoint. Inherits a’s non-adjacency: two surviving pieces are always separated by a removed point.

When either input holds an odd number of bounds.