Recently, I have been reading up on few blogs about rolling hash: dacin21's [On the mathematics behind rolling hashes and anti-hash tests] and rng_58's [Hashing and Probability of Collision]. Both of them showcase different hashing technique.
Method described in dacin21's blog:
Note: in the above equation a is the base
Method described in rng_58's blog:
H(a) = (r+a_1)(r+a_2)...(r+a_n)
Note: in the above equation r is the base
Are there any differences between the two in terms of use-case and other parameters? Which one do you recommend? Also, if possible can you please share your implementation of rolling hash if you have ever used it to solve any problem. Thanks!
rng's method only applies to multisets, not strings. Don't use it for strings.