【ToolGood.Words】之【StringSearch】字符串搜索——基於BFS算法


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM