字符串搜索中,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