When hashing a (key, value) pair where the key is a string, I have seen the following hash function in use:
E.g. $c_n + 256c_{n-1}+ 256^2c_{n-2}+...256^{n-1}c_1$, where this represents the string $c_1c_2..c_n$. I understand the equation above can be written as: $c_n + 256(c_{n-1} + 256(c_{n-2}+...256c_1))$, could someone explain how the following is valid, when I have to compute mod over the entire sum, how can we take it term by term?
r= 0;
for i = 1 to n do
r := (c[i] + 256*r) mod TableSize