進位制雜湊

9102700發表於2024-05-30

無論我變成什麼樣子,我始終是指向你的

來記錄一下進位制雜湊和比較大的模數

點選檢視程式碼
#define ull unsigned long long
ull BKDRHash(string s){

    const ll m1 = 89999794200117649;
    const ll m2 = 999999786000011449;
    const ll m3 = 1000000000000002217;
    const ll m4 = 100000000000001921;
    ull P = 131, H = 0; // P 也可以是 13131  131313
    int n = s.size();
    for(int i = 0; i < n; i++){
        H = H*P + s[i];
    }
    return H;
}

相關文章