Trie 字典树 Objective-c 算法实现

下载地址: http://github.com/nathanday/ndtrie

NDTrie was developed for text completion, using the method -[NDTrie everyObjectForKeyWithPrefix:] will return every
string with the given prefix. For example an NDTrie with the strings {cat, catalog, category, cow, dog} for
everyObjectForKeyWithPrefix:@"cat" return the strings {cat, catalog, category}.
The NDTrie project contains two classes NDTrie and a subclass NDMutableTrie, which work the same way Apples mutable and
non-mutable classes work.
Though initially developed to contain strings that act as the key and value using methods like -[NSMutableTrie
addString:], NDTrie can also contain any object with a string key using methods like -[NSMutableTrie
setObject:forKey:].

之所以选择这个开源组件,是我着手开发一个英文字段软件。
词库量较大,有4W条记录,通过sqlite的like查询,效率很低。使用了这个组件之后,效果更差!
最终的解决方法还是在数据库上做文章,首先根据单词顺序进行排序,分别记录不同字母开头单词所在区域,其次创建索引,查询时,根据用户输入的关键字,再给定范围内进行模糊查询。目前速度还算满意。

你可能感兴趣的:(C++,c,算法,Objective-C,C#)