summaryrefslogtreecommitdiff
path: root/girepository/cmph/sdbm_hash.c
blob: 2f706c9ff8d6f81b302a7ccc873e34ffb65c4fb6 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "sdbm_hash.h"
#include <stdlib.h>

sdbm_state_t *sdbm_state_new()
{
	sdbm_state_t *state = (sdbm_state_t *)malloc(sizeof(sdbm_state_t));
	state->hashfunc = CMPH_HASH_SDBM;
	return state;
}

void sdbm_state_destroy(sdbm_state_t *state)
{
	free(state);
}

cmph_uint32 sdbm_hash(sdbm_state_t *state, const char *k, cmph_uint32 keylen)
{
	register cmph_uint32 hash = 0;
	const unsigned char *ptr = (unsigned char *)k;
	cmph_uint32 i = 0;

	while(i < keylen) {
		hash = *ptr + (hash << 6) + (hash << 16) - hash;
		++ptr, ++i;
	}
	return hash;
}


void sdbm_state_dump(sdbm_state_t *state, char **buf, cmph_uint32 *buflen)
{
	*buf = NULL;
	*buflen = 0;
	return;
}

sdbm_state_t *sdbm_state_copy(sdbm_state_t *src_state)
{
	sdbm_state_t *dest_state = (sdbm_state_t *)malloc(sizeof(sdbm_state_t));
	dest_state->hashfunc = src_state->hashfunc;
	return dest_state;
}

sdbm_state_t *sdbm_state_load(const char *buf, cmph_uint32 buflen)
{
	sdbm_state_t *state = (sdbm_state_t *)malloc(sizeof(sdbm_state_t));
	state->hashfunc = CMPH_HASH_SDBM;
	return state;
}