Ray's playground

 

Data Structures(Chapter 3 of The Algorithm Design Manual)

Rabin–Karp string search algorithm

function RabinKarp(string s[1..n], string sub[1..m])

hsub := hash(sub[1..m]); hs := hash(s[1..m])

for i from 1 to n-m+1

if hs = hsub

if s[i..i+m-1] = sub

return i

hs := hash(s[i+1..i+m])

return not found 

posted on 2010-09-21 12:56  Ray Z  阅读(2060)  评论(0编辑  收藏  举报

导航