2023-09-05 10:44:52 -05:00
|
|
|
/* cdb_hash.c: cdb hashing routine
|
|
|
|
*
|
2023-09-18 07:36:07 -05:00
|
|
|
* This file is a part of tinycdb package by Michael Tokarev, mjt+cdb@corpit.ru.
|
2023-09-05 10:44:52 -05:00
|
|
|
* Public domain.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cdb.h"
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
cdb_hash(const void *buf, unsigned len)
|
|
|
|
{
|
|
|
|
register const unsigned char *p = (const unsigned char *)buf;
|
|
|
|
register const unsigned char *end = p + len;
|
|
|
|
register unsigned hash = 5381; /* start value */
|
|
|
|
while (p < end)
|
|
|
|
hash = (hash + (hash << 5)) ^ *p++;
|
|
|
|
return hash;
|
|
|
|
}
|