1
Fork 0
turbonss/src/sdbm_hash.c

43 lines
921 B
C
Raw Normal View History

2004-12-23 15:16:30 +02:00
#include "sdbm_hash.h"
#include <stdlib.h>
2005-01-18 23:06:08 +02:00
cmph_sdbm_state_t *cmph_sdbm_state_new()
2004-12-23 15:16:30 +02:00
{
2005-01-18 23:06:08 +02:00
cmph_sdbm_state_t *state = (cmph_sdbm_state_t *)malloc(sizeof(cmph_sdbm_state_t));
state->hashfunc = CMPH_HASH_SDBM;
2004-12-23 15:16:30 +02:00
return state;
}
2005-01-18 23:06:08 +02:00
void cmph_sdbm_state_destroy(cmph_sdbm_state_t *state)
2004-12-23 15:16:30 +02:00
{
free(state);
}
2005-01-18 23:06:08 +02:00
cmph_uint32 cmph_sdbm_hash(cmph_sdbm_state_t *state, const char *k, cmph_uint32 keylen)
2004-12-23 15:16:30 +02:00
{
2005-01-18 23:06:08 +02:00
register cmph_uint32 hash = 0;
2004-12-23 15:16:30 +02:00
const unsigned char *ptr = k;
2005-01-18 23:06:08 +02:00
cmph_uint32 i = 0;
2004-12-23 15:16:30 +02:00
while(i < keylen) {
hash = *ptr + (hash << 6) + (hash << 16) - hash;
++ptr, ++i;
}
return hash;
}
2005-01-18 23:06:08 +02:00
void cmph_sdbm_state_dump(cmph_sdbm_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_sdbm_state_t *cmph_sdbm_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_sdbm_state_t *state = (cmph_sdbm_state_t *)malloc(sizeof(cmph_sdbm_state_t));
state->hashfunc = CMPH_HASH_SDBM;
2004-12-23 15:16:30 +02:00
return state;
}