Skip to content

compressedSegmentedTrie<V>(entries?): SegmentedTrie<V>

Defined in: packages/trie/src/compressed-segmented-trie.ts:186

Create a SegmentedTrie that packs runs of non-branching segments into edge labels: the path compression a radix tree applies to characters, applied here to whole segments.

A node exists only where keys branch or end. Keys always end at nodes: an insert whose key runs out inside an edge splits the edge around a fresh node. delete prunes nodes it empties and folds a resulting single-child chain back into its parent’s edge, so the layout holds one node per branch point or key end of the live keys, whatever the operation history.

The observable contract matches uncompressedSegmentedTrie exactly. The trade is in the constants: fewer nodes, and one Map lookup per edge instead of one per segment during a walk, against edge comparisons on every operation and split bookkeeping on insert. Prefer it when keys are deep or mostly non-branching, the shapes that also make its smaller node count matter.

V

Iterable<SegmentedTrieEntry<V>, any, any>

Key-value pairs to store, in iteration order. A repeated key overwrites the earlier value, mirroring Map, and entries before an invalid one stay stored.

SegmentedTrie<V>

When an entry key is not an array of strings.