Reformat comment
This commit is contained in:
@@ -12,19 +12,19 @@
|
|||||||
djb2 string hash
|
djb2 string hash
|
||||||
credits: Daniel J. Bernstein
|
credits: Daniel J. Bernstein
|
||||||
|
|
||||||
Returns a hash of the string `str`.
|
Returns a hash of the string `str`.
|
||||||
|
|
||||||
It seems to work well because 33 is coprime to
|
It seems to work well because 33 is coprime to
|
||||||
2^32 and 2^64 (any odd number except 1 is),
|
2^32 and 2^64 (any odd number except 1 is),
|
||||||
which probably improves the distribution
|
which probably improves the distribution (I'm
|
||||||
(I'm not a mathematician so I can't prove it this).
|
not a mathematician so I can't prove it this).
|
||||||
Multiplying a number n by 33 is the same as
|
Multiplying a number n by 33 is the same as
|
||||||
bitshifting by 5 and adding n, which is faster
|
bitshifting by 5 and adding n, which is faster
|
||||||
than multiplying by, say, 37. Maybe any 2^x±1
|
than multiplying by, say, 37. Maybe any 2^x±1
|
||||||
are equally good.
|
are equally good.
|
||||||
|
|
||||||
5381 is a large-ish prime number which are used
|
5381 is a large-ish prime number which are used
|
||||||
as multipliers in most hash algorithms.
|
as multipliers in most hash algorithms.
|
||||||
*/
|
*/
|
||||||
size_t obj_hash(char const* str)
|
size_t obj_hash(char const* str)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user