快速索引和QUOT;包含字符串"字符串、索引、快速、QUOT

2023-09-11 22:56:19 作者:你成了我梦里最美的谎言

I N我的应用程序已经UPTØ数以百万计的短字符串(大多少于32个字符)。我想实现一个连接列表,其中包含只有包含在搜索框中输入的整个字符串元素的搜索框。我怎样才能prebuild一个索引来查找这样的字符串快?所有排序的STL容器检查整个字符串。

I n my application i have upt o millions of short strings (mostly shorter than 32 characters). I want to implement a search box with a attached list that contains only elements that contain the whole string entered in the search box. How can i prebuild a index to find such strings fast? All sorted STL containers check the whole string.

对于输入的搜索字符串海峡我需要找到containg海峡的所有字符串:大街,司徒卢威,美国贸易代表办公室等

For a entered search string "str" i need to find all strings containg "str": "main street", "struve", "ustr" etc.

推荐答案

您可以建立一个的轮排索引的。

有关司徒卢威你会插入一个基数树(或通用搜索树):

For "struve" you would insert into a Radix tree (or a general purpose search tree):

struve$
truve$s
ruve$st
uve$str
ve$stru
e$struv
$struve

要搜索,你会从根节点搜索匹配preFIX串缀。

To search the infix you would search from the root node for matching prefix strings.