pkg.mk: website: dark216 to save electricity
[ruby-tdb.git] / ext / tdb / djb.c
blob83abe34931ac67442a209820166f047512e5001a
1 #include "rbtdb.h"
3 unsigned int rbtdb_djb2(TDB_DATA *data)
5 unsigned char *key = data->dptr;
6 size_t len = data->dsize;
7 unsigned int hash = 5381;
8 unsigned int i;
10 for (i = 0; i < len; ++i)
11 hash = ((hash << 5) + hash) + key[i]; /* (hash*33) + key[i] */
13 return hash;
15 unsigned int rbtdb_djb3(TDB_DATA *data)
17 unsigned char *key = data->dptr;
18 size_t len = data->dsize;
19 unsigned int hash = 5381;
20 unsigned int i;
22 for (i = 0; i < len; ++i)
23 hash = ((hash << 5) + hash) ^ key[i]; /* (hash*33) ^ key[i] */
25 return hash;