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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”readonly T[]
Flat [start, end, …] pairs, ascending and disjoint.
readonly T[]
The holes to remove, ascending and disjoint.
compare
Section titled “compare”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.
Returns
Section titled “Returns”T[]
A fresh flat array, ascending and disjoint. Inherits a’s
non-adjacency: two surviving pieces are always separated by a removed
point.
Throws
Section titled “Throws”When either input holds an odd number of bounds.