toolgood

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

字符串搜索中,BFS算法很巧妙,个人认为BFS算法效率是最高的。

【StringSearch】就是根据BFS算法并优化。

使用方法:

string s = "中国|国人|zg人|fuck|all|as|19|http://|ToolGood";

string test = "我是中国人";

StringSearch ss = new StringSearch(); 

ss.SetKeywords(s.Split('|'));             

var allss = ss.FindAll(test);

 

【StringSearch】在目前已知的公开的算法中,效率最高。

TextSearch : 141ms

TrieFilter : 158ms

FastFilter : 105ms

StringSearch : 30ms

IllegalWordsSearch jump 1 : 770ms

IllegalWordsSearch jump 2 : 729ms

----------------------- Find All -----------------------------------

TextSearch : 1,488ms

TrieFilter : 1,333ms

FastFilter : 301ms

StringSearch : 358ms

IllegalWordsSearch jump 1 : 3,070ms

IllegalWordsSearch jump 2 : 3,213ms

注: 在 Find All测试中,FastFilter只能检测出7个,StringSearch检测出14个

项目地址:

https://github.com/toolgood/ToolGood.Words

参考文章:

http://www.cnblogs.com/yeerh/archive/2011/10/20/2219035.html

http://www.cnblogs.com/xingd/archive/2008/02/01/1061800.html

 

posted on 2016-12-25 14:53  ToolGood  阅读(2037)  评论(0编辑  收藏  举报