Skip to content

Instantly share code, notes, and snippets.

@KScaesar
Last active April 13, 2019 09:46
Show Gist options
  • Select an option

  • Save KScaesar/f9e5dd252d9d86992c1f64a07aaa7c62 to your computer and use it in GitHub Desktop.

Select an option

Save KScaesar/f9e5dd252d9d86992c1f64a07aaa7c62 to your computer and use it in GitHub Desktop.
Rabin-Karp 演算法 多模式匹配
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