Prefix search through list/dictionary using .NET StringDictionary?

℡╲_俬逩灬. 提交于 2019-12-01 09:41:01
jason

StringDictionary is merely a hash table where the keys and values are strings. This existed before generics (when Dictionary<string, string> was not possible).

The data structure that you want here is a trie. There are implementations on CodeProject:

  1. Phone Directory Implementation Using TRIE
  2. A Reusable Prefix Tree using Generics in C# 2.0

Or, if you're that kind of guy, roll your own (see CLRS).

I don't believe StringDictionary supports a prefix search, but if you use a SortedList<,> you can binary search through the range of keys until you find the first entry before and after your prefix.

I think the StringDictionary is old school (pre-generics). You should probably use a Dictionary(Of String, String) instead because it implements IEnumerable (think LINQ). One extremely lame thing about StringDictionary is that it's case-insensitive.

I made a generic implementation of this available here.

Since string implements IEnumerable<char>, you can use it with char as parameter for TKeyElement.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!