Last active
April 13, 2019 09:46
-
-
Save KScaesar/f9e5dd252d9d86992c1f64a07aaa7c62 to your computer and use it in GitHub Desktop.
Rabin-Karp 演算法 多模式匹配
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function RabinKarpSet(string s[1~K], string patterns[1~N]) | |
| //用hash table or Cuckoo Filter 來儲存敏感詞彙相關資料 | |
| set hsSet := emptySet | |
| //前置處理 | |
| foreach p in patterns | |
| insert hash(p[1~M]) into hsSet | |
| hs := hash(s[1~M]) | |
| //匹配運算 | |
| for i from 1 to K-M+1 | |
| if hs ∈ hsSet and s[i~i+M-1] ∈ patterns | |
| return i | |
| hs := hash(s[i+1..i+M]) | |
| return not found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment