📜  字符串哈希 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:55.449000             🧑  作者: Mango

代码示例1
long long compute_hash(string const& s) {
    const int p = 53;
    const int m = 1e9 + 9;
    long long hash_value = 0;
    long long p_pow = 1;
    for (char c : s) {
        hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
        p_pow = (p_pow * p) % m;
    }
    return hash_value;
}