单词索引技术

Single word indexing technique

假设我有一个大数组,其中每个元素都是一个单词,我想建立一个索引。

Water这个词,我可以写一个returns

的函数
w
wa
wat
wate
water
at
ate
ater
ter
er
r

这些结果将是散列中的键 table,其中值是包含键的单词数组。

鉴于我不关心内存消耗,并且数据是只读的,即仅在应用程序启动时插入:

我想你正在寻找 Trie:

a trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes), is a kind of search tree—an ordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings.