For example, the expression
produces a four-byte hash value. This particular expression is bad because each call to(hash(v, n) << 24) + (hash(v, n) << 16) + (hash(v, n) << 8) + hash(v, n)
hash()
returns the same value, greatly degrading the randomness
of the resulting multi-byte hash value.
There are a couple of ways to fix this problem. One is to have four hash functions, each with a different random permutation.
Another is to change(hash0(v, n) << 24) + (hash1(v, n) << 16) + (hash2(v, n) << 8) + hash3(v, n)
hash()
to accept a seed used to initialize the
hash value.
and create multi-byte has values withbyte hash(byte v[], unsigned n, unsigned seed) byte h = rp[seed % 256] for i = 0 to n - 1 h = h xor rp[v[i]] return h
(hash(v, n, 0) << 24) + (hash(v, n, 1) << 16) + (hash(v, n, 2) << 8) + hash(v, n, 3)
This page last modified on 24 January 2006.