ruby-tdb.git  about / heads / tags
Trivial Database bindings for Ruby
blob 83abe34931ac67442a209820166f047512e5001a 534 bytes (raw)
$ git show HEAD:ext/tdb/djb.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
 
#include "rbtdb.h"

unsigned int rbtdb_djb2(TDB_DATA *data)
{
	unsigned char *key = data->dptr;
	size_t len = data->dsize;
	unsigned int hash = 5381;
	unsigned int i;

	for (i = 0; i < len; ++i)
		hash = ((hash << 5) + hash) + key[i]; /* (hash*33) + key[i] */

	return hash;
}
unsigned int rbtdb_djb3(TDB_DATA *data)
{
	unsigned char *key = data->dptr;
	size_t len = data->dsize;
	unsigned int hash = 5381;
	unsigned int i;

	for (i = 0; i < len; ++i)
		hash = ((hash << 5) + hash) ^ key[i]; /* (hash*33) ^ key[i] */

	return hash;
}

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