1
Fork 0
turbonss/src/fnv_hash.c

47 lines
1.0 KiB
C
Raw Normal View History

2004-12-23 15:16:30 +02:00
#include "fnv_hash.h"
#include <stdlib.h>
2005-01-18 23:06:08 +02:00
cmph_fnv_state_t *cmph_fnv_state_new()
2004-12-23 15:16:30 +02:00
{
2005-01-18 23:06:08 +02:00
cmph_fnv_state_t *state = (cmph_fnv_state_t *)malloc(sizeof(cmph_fnv_state_t));
state->hashfunc = CMPH_HASH_FNV;
2004-12-23 15:16:30 +02:00
return state;
}
2005-01-18 23:06:08 +02:00
void cmph_fnv_state_destroy(cmph_fnv_state_t *state)
2004-12-23 15:16:30 +02:00
{
free(state);
}
2005-01-18 23:06:08 +02:00
cmph_uint32 cmph_fnv_hash(cmph_fnv_state_t *state, const char *k, cmph_uint32 keylen)
2004-12-23 15:16:30 +02:00
{
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;
}
2005-01-18 23:06:08 +02:00
void cmph_fnv_state_dump(cmph_fnv_state_t *state, char **buf, cmph_uint32 *buflen)
2004-12-23 15:16:30 +02:00
{
*buf = NULL;
*buflen = 0;
return;
}
2005-01-18 23:06:08 +02:00
cmph_fnv_state_t *cmph_fnv_state_load(const char *buf, cmph_uint32 buflen)
2004-12-23 15:16:30 +02:00
{
2005-01-18 23:06:08 +02:00
cmph_fnv_state_t *state = (cmph_fnv_state_t *)malloc(sizeof(cmph_fnv_state_t));
state->hashfunc = CMPH_HASH_FNV;
2004-12-23 15:16:30 +02:00
return state;
}