ruby-tdb.git  about / heads / tags
Trivial Database bindings for Ruby
blob 769a3d7be0b386177debb00b236d4b609fb45217 640 bytes (raw)
$ git show HEAD:ext/tdb/fnv.c	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;
}

git clone https://yhbt.net/ruby-tdb.git