Stores keys in comparator order with insertion, deletion, rank, selection, ceiling, floor, and range scans in either direction, as a B-tree or an indexed skip list
Create an empty B-tree ordered map: a B+ tree with linked leaves and per-child entry counts on each branch.
Supply a stable total order and keep comparison keys unchanged while stored. The order may not mutate the map.
Every search, write, rank, selection, ceiling and floor takes worst-case O(log n) time. A bounded walk in either
direction costs one descent plus O(k) for k results.
@see ― Douglas Comer, The Ubiquitous B-Tree, ACM Computing Surveys 11(2), 1979.
Create an empty B-tree ordered map: a B+ tree with linked leaves and per-child entry counts on each branch.
Supply a stable total order and keep comparison keys unchanged while stored. The order may not mutate the map.
Every search, write, rank, selection, ceiling and floor takes worst-case O(log n) time. A bounded walk in either
direction costs one descent plus O(k) for k results.
@see ― Douglas Comer, The Ubiquitous B-Tree, ACM Computing Surveys 11(2), 1979.
For each size, 128 seeded bounds count the keys at or below the bound.
At 2,048 keys, average comparisons per query: 21.2 indexed, 992.1 for a sequential scan.
Use the indexed map for rank, positional reads, and ordered walks over changing keys.
Hover or focus a chart for exact values. Each change reruns demo.ts against knotkit/ordered-map in your browser; the defaults reproduce the README figure.
Every error this module throws is OrderedMapInvalidInputError, with a code from a closed, exported list. Branch on the code; the message is for people.
Use knotkit/ordered-map for this task. If Knotkit is missing, follow https://knotkit.jkomyno.dev/getting-started.md#install-from-source. Import from 'knotkit/ordered-map'.
Exports:
- `bTreeOrderedMap` → `OrderedMap<K, V>`: B+ tree with 64-entry linked leaves and 64-child branches that count the entries under each child.
- `indexedSkipListOrderedMap` → `OrderedMap<K, V>`: Comparator-keyed skip list with a span on each forward link and a predecessor link on the base level.
Pick the layout by these rules:
- `bTreeOrderedMap` (kind 'b-tree') when keys change between point, rank, selection or range queries, a comparator defines key equality, and the layout needs no injected random source
- `indexedSkipListOrderedMap` (kind 'indexed-skip-list') when the layout must draw its shape from an injected RandomSource, such as replaying a skip list recorded under a known seed
Inputs and their sources:
- key order: `Order<K>` from `knotkit/heap`
- tower heights for indexed-skip-list (defaults to splitmix32(0)): `RandomSource` from `knotkit/prng`
Use something else when:
- only keyed lookup with identity equality → Map
- rank and selection over bounded unsigned integer IDs without payloads → knotkit/bitset
- only the smallest or largest element of a changing queue → knotkit/heap
- an immutable sorted block of byte-keyed entries with seeks → knotkit/sorted-block
Errors are OrderedMapInvalidInputError with a `code` property. Branch on `error.code`, never on the message.
Full page: https://knotkit.jkomyno.dev/modules/ordered-map.md
Types: node_modules/knotkit/ordered-map/ and https://knotkit.jkomyno.dev/reference/knotkit/ordered-map/