String hash function #2
-
A more effective approach is to compute a polynomial whose coefficients are the integer values of the chars in the String
-
For example, for a String s with length n+1, we might compute a polynomial in
x
... and take the result mod the size of the table.
-
Horner’s rule can be used to compute
H
(s) with n+1 iterations:
-
... etc. It is interesting to compare this to the basic form of a linear congruential random number generator; there is a relation between good hashing and apparent randomness:
CONTENTS PREVIOUS NEXT