string hashing

core idea

substrings

For the substring , let . Then

where is the modular inverse of modulo .

so you basically store prefix hashes and filter out the leading coefficient to make it 1.

improving non-collision rate

a hash is defined in terms of a tuple (p,m)

Ideally you would have m to be a large prime and keep it constant and then just use several differen p’s

so hash then becomes a vector of ints for the ordered tuple (p1,p2,p3) and the same m used across.

some applications

  • a cyclic shift invariant hash? can be computed in linear time as the