Would Dan Bernstein’s hash function still function properly if I was using a 64 bit unsigned integer?
uint64
hash_djb2(register uchar *str, register size_t length) {
register uint64 hash = 5381L;
while (length--) {
hash = ((hash << 5L) + hash) + *str++; /* hash * 33 + c */
}
return hash;
}
I don’t know if the distribution across all 2^64 possible values will be the same as the 32-bit version, but one important property still holds. The multiplier
33does not share any common divisors with 2^64. As a result, all characters run through the hash will still have an affect on the final result. In other words, the hash result for these two strings will be different:It should still be a useful hash function. And of course, I can’t help but wonder why you need hash values this large. A very large hash table? Or some other use?