hashes.djb2¶
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];
First Magic constant 33: It has never been adequately explained. It’s magic because it works better than many other constants, prime or not.
Second Magic Constant 5381:
odd number
prime number
deficient number
001/010/100/000/101 b
Functions¶
|
Implementation of djb2 hash algorithm that |
Module Contents¶
- hashes.djb2.djb2(s: str) int ¶
Implementation of djb2 hash algorithm that is popular because of it’s magic constants.
>>> djb2('Algorithms') 3782405311
>>> djb2('scramble bits') 1609059040