我在 Topcoder 阅读 Rabin Karp 算法。但是在那篇文章中,我无法获得以下哈希评估。
// calculate the hash value of the first segment
// of the text of length m
ht = 0;
for(i = 0; i < m; i++)
ht = int_mod(ht * B + text[i], M);
它看起来与理论中解释的不同。我知道我可以自由地使用 Rabin Karp 中的任何哈希函数,但仍然要保持教程的流程,我需要解释一下,因为我可能没有正确理解它。