Loading...
Searching...
No Matches

djb2 hash algorithm.

djb2 hash algorithm.

HISTORY This algorithm (k=33) was first reported by Dan Bernstein many years ago in comp.lang.c. Another version of this algorithm (now favored by bernstein) uses XOR:

 hash(i) = hash(i - 1) * 33 ^ str[i];

The magic of number 33 (why it works better than many other constants, prime or not) has never been adequately explained.

Parameters
bufinput buffer to hash
lenlength of buffer
Returns
32 bit sized hash