Prefix search retrieves every stored string beginning with a specified prefix. It is a natural operation for a string container and supports applications such as spell-checking and other prefix-oriented lookup tasks. section 6.1.3
A string container can expose prefix search alongside ordinary container operations:
- insert, remove, and contains manage stored strings. section 6.1.3
- keysStartingWith(prefix) returns all stored strings beginning with prefix. section 6.1.3
- A trie locates the prefix endpoint, then traverses the subtree rooted there to enumerate matching keys. section 6.3.6
- A radix trie must also handle a prefix ending inside a compressed edge; a partial match can identify a descendant subtree even without a node at the prefix endpoint. section 6.3.6
Compressed-edge matching
Suppose the requested prefix is not explicitly stored in a radix trie. If the remaining prefix fully matches the beginning of an edge, searchNodeWithPrefix returns that edge's destination and enumeration continues through its descendants; an incomplete match returns null. section 6.3.6
Table 6.1 API and contract for StringContainer (view table figure)
Use the API contract to compare exact lookup, longest-prefix lookup, and retrieval of every key starting with a prefix. section 6.1.3
For a trie, prefix search runs in O(n + m) in the comparison table, where n is the number of returned or traversed keys and m is the average key length. Tries favor frequent prefix searches but consume memory for nodes and child references; profile alternatives when memory locality or storage costs dominate. section 6.2.7
