File: fnv_hash.c

package info (click to toggle)
gobject-introspection 1.84.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 72,336 kB
  • sloc: ansic: 562,269; python: 23,692; xml: 16,240; yacc: 1,711; perl: 1,624; sh: 1,139; lex: 510; cpp: 487; makefile: 182; javascript: 15; lisp: 1
file content (53 lines) | stat: -rw-r--r-- 1,161 bytes parent folder | download | duplicates (10)
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
50
51
52
53
#include "fnv_hash.h"
#include <stdlib.h>

fnv_state_t *fnv_state_new()
{
	fnv_state_t *state = (fnv_state_t *)malloc(sizeof(fnv_state_t));
	state->hashfunc = CMPH_HASH_FNV;
	return state;
}

void fnv_state_destroy(fnv_state_t *state)
{
	free(state);
}

cmph_uint32 fnv_hash(fnv_state_t *state, const char *k, cmph_uint32 keylen)
{
	const unsigned char *bp = (const unsigned char *)k;	
	const unsigned char *be = bp + keylen;	
	static unsigned int hval = 0;	

	while (bp < be) 
	{
		
		//hval *= 0x01000193; good for non-gcc compiler
		hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24); //good for gcc

		hval ^= *bp++;
	}
	return hval;
}


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

fnv_state_t * fnv_state_copy(fnv_state_t *src_state)
{
	fnv_state_t *dest_state = (fnv_state_t *)malloc(sizeof(fnv_state_t));
	dest_state->hashfunc = src_state->hashfunc;
	return dest_state;
}

fnv_state_t *fnv_state_load(const char *buf, cmph_uint32 buflen)
{
	fnv_state_t *state = (fnv_state_t *)malloc(sizeof(fnv_state_t));
	state->hashfunc = CMPH_HASH_FNV;
	return state;
}