| 1 |
/* cdb hashing routine
|
| 2 |
*
|
| 3 |
* This file is a part of tinycdb package by Michael Tokarev, mjt@corpit.ru.
|
| 4 |
* Public domain.
|
| 5 |
*/
|
| 6 |
|
| 7 |
#include "common/setup_before.h"
|
| 8 |
#include "cdb.h"
|
| 9 |
#include "common/setup_after.h"
|
| 10 |
|
| 11 |
unsigned
|
| 12 |
cdb_hash(const void *buf, unsigned len)
|
| 13 |
{
|
| 14 |
register const unsigned char *p = (const unsigned char *)buf;
|
| 15 |
register const unsigned char *end = p + len;
|
| 16 |
register unsigned hash = 5381; /* start value */
|
| 17 |
while (p < end)
|
| 18 |
hash = (hash + (hash << 5)) ^ *p++;
|
| 19 |
return hash;
|
| 20 |
}
|