哪种数据结构用于快速搜索? (C#)

Which data structure to use for fast search? (C#)

我需要一个高效的数据结构来进行搜索。目前我正在使用 System.Collections.Generic 中的一个简单列表,直到找到一个好的解决方案。

用户可以在运行时通过在列表中单击字符串来 add/remove 字符串。但主要操作是搜索,因为每次用户想要查看列表时,如果用户之前已经点击过,我需要检查每个条目。该列表可能包含大约 100-1000 个条目,用户可以从中选择大约 100 个。包含所选字符串的列表也将作为字符串数组保存到磁盘,需要再次加载。因此,如果数组以正确的顺序保存,数据结构应该可以快速从字符串数组重建。

我考虑过使用 AVL 树。这是一个好的解决方案吗?还是可以散列(我不知道编译时可以选择的字符串)?

由于您使用的是 C#,我建议使用:Dictionary. It will allow you to store strings in a Hash Map (which is a related to Java's Map). The benefit of storing strings in a Dictionary is similar to that of a hash table which will allow constant time of searching, inserting, and deleting. Should you want to check if there are duplicate values you can check here for more information: Finding duplicate values in dictionary and print Key of the duplicate element