Skip to content

sortedArrayIntervalIndex<K, V>(order, initialEntries?): IntervalIndex<K, V>

Defined in: packages/interval-index/src/sorted-array-interval-index.ts:37

Create an interval index backed by one array of entries sorted by (start, id) and a parallel array whose i-th key is the largest end among the first i + 1 entries, plus a map from id to entry.

Construction from n initial entries takes O(n log n) time. An add whose start sorts at or after the last stored start appends in O(1) amortized time; any other add takes O(1). A successful delete takes amortized O(1), compacting in O(n) when half the entries have been deleted. Both operations leave the query index to be rebuilt by the next query or walk, in O(n log n) after an out-of-order add and O(n) after deletions alone. has and get take O(1). A settled atPoint or overlapping takes O(log n + m) time, where m counts the entries between the first one whose running maximum end reaches the query start and the last one starting at or before the query end; m is at least the k entries reported and at most n. A full walk takes O(n). Space is O(n).

K

V

Order<K>

Iterable<IntervalInput<K, V>, any, any>

IntervalIndex<K, V>

With INVALID_INTERVAL when an initial entry’s start sorts after its end.