From 58938c980f38a4581b4a0e8a780fffe7ac95bc93 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 26 Nov 2010 02:27:17 +0000 Subject: initial --- ext/tdb/fnv.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ext/tdb/fnv.c (limited to 'ext/tdb/fnv.c') diff --git a/ext/tdb/fnv.c b/ext/tdb/fnv.c new file mode 100644 index 0000000..769a3d7 --- /dev/null +++ b/ext/tdb/fnv.c @@ -0,0 +1,28 @@ +#include "rbtdb.h" + +#define FNV1A_32A_INIT (unsigned int)0x811c9dc5 +#define FNV_32_PRIME (unsigned int)0x01000193 + +unsigned int rbtdb_fnv1a(TDB_DATA * data) +{ + unsigned char *bp = data->dptr; + unsigned char *be = bp + data->dsize; + unsigned int h = FNV1A_32A_INIT; + + /* FNV-1a hash each octet in the buffer */ + while (bp < be) { + + /* xor the bottom with the current octet */ + h ^= (unsigned)*bp++; + + /* multiply by the 32 bit FNV magic prime mod 2^32 */ +#if defined(NO_FNV_GCC_OPTIMIZATION) + h *= FNV_32_PRIME; +#else + h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24); +#endif + } + + /* return our new hash value */ + return h; +} -- cgit v1.2.3-24-ge0c7