# sortedArrayIntervalIndex

> **sortedArrayIntervalIndex**<`K`, `V`>(`order`, `initialEntries?`): [`IntervalIndex`](/reference/knotkit/interval-index/interfaces/intervalindex/)<`K`, `V`>

Defined in: [packages/interval-index/src/sorted-array-interval-index.ts:37](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/interval-index/src/sorted-array-interval-index.ts#L37)

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).

## Type Parameters

### K

`K`

### V

`V`

## Parameters

### order

[`Order`](/reference/knotkit/heap/type-aliases/order/)<`K`>

### initialEntries?

`Iterable`<[`IntervalInput`](/reference/knotkit/interval-index/type-aliases/intervalinput/)<`K`, `V`>, `any`, `any`>

## Returns

[`IntervalIndex`](/reference/knotkit/interval-index/interfaces/intervalindex/)<`K`, `V`>

## Throws

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