我正在寻找一种高效的哈希函数用于Rabin-Karp算法。这是我的实际代码(C编程语言)。
static bool f2(char const *const s1, size_t const n1,
char const *const s2, size_t const n2)
{
uintmax_t hsub = hash(s2, n2);
uintmax_t hs = hash(s1, n1);
size_t nmax = n2 - n1;
for (size_t i = 0; i < nmax; ++i) {
if (hs == hsub) {
if (strncmp(&s1[i], s2, i + n2 - 1) == 0)
return true;
}
hs = hash(&s1[i + 1], i + n2);
}
return false;
}
我考虑了一些Rabin-Karp的C语言实现,但是这些代码之间都存在差异。因此我的问题是:一个Rabin-Karp哈希函数应该具备哪些特性?