1 /* $Id: cdb_hash.c,v 1.5 2003/11/03 16:42:41 mjt Exp $
2 * cdb hashing routine
3 *
4 * This file is a part of tinycdb package by Michael Tokarev, mjt@corpit.ru.
5 * Public domain.
6 */
7
8 #include <config.h>
9
10 #include "cdb.h"
11
12 unsigned
cdb_hash(const void * buf,unsigned len)13 cdb_hash(const void *buf, unsigned len)
14 {
15 const unsigned char *p = (const unsigned char *)buf;
16 const unsigned char *end = p + len;
17 unsigned hash = 5381; /* start value */
18 while (p < end)
19 hash = (hash + (hash << 5)) ^ *p++;
20 return hash;
21 }
22