doc: s/bogomips.org/yhbt.net/
[ruby-tdb.git] / ext / tdb / fnv.c
blob769a3d7be0b386177debb00b236d4b609fb45217
1 #include "rbtdb.h"
3 #define FNV1A_32A_INIT (unsigned int)0x811c9dc5
4 #define FNV_32_PRIME (unsigned int)0x01000193
6 unsigned int rbtdb_fnv1a(TDB_DATA * data)
8 unsigned char *bp = data->dptr;
9 unsigned char *be = bp + data->dsize;
10 unsigned int h = FNV1A_32A_INIT;
12 /* FNV-1a hash each octet in the buffer */
13 while (bp < be) {
15 /* xor the bottom with the current octet */
16 h ^= (unsigned)*bp++;
18 /* multiply by the 32 bit FNV magic prime mod 2^32 */
19 #if defined(NO_FNV_GCC_OPTIMIZATION)
20 h *= FNV_32_PRIME;
21 #else
22 h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24);
23 #endif
26 /* return our new hash value */
27 return h;