MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / hasher

Method hasher

code/strings/hasher.cpp:2–6  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1struct hasher { int b = 311, m; vi h, p;
2 hasher(string s, int _m)
3 : m(_m), h(size(s)+1), p(size(s)+1) {
4 p[0] = 1; h[0] = 0;
5 rep(i,0,size(s)) p[i+1] = (ll)p[i] * b % m;
6 rep(i,0,size(s)) h[i+1] = ((ll)h[i] * b + s[i]) % m; }
7 int hash(int l, int r) {
8 return (h[r+1] + m - (ll)h[l] * p[r-l+1] % m) % m; } };
9// vim: cc=60 ts=2 sts=2 sw=2:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected