summaryrefslogtreecommitdiff
path: root/girepository/cmph/fnv_hash.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2010-11-11 15:01:07 -0500
committerColin Walters <walters@verbum.org>2010-11-16 17:01:07 -0500
commit9bf6ff0e49391c7aee76b2fcb6e479a34e19c058 (patch)
tree79f40cb50da5a4f23f8efeee20612fa9708d2930 /girepository/cmph/fnv_hash.c
parentc9d0441f7c8fb33f313ba65b11cb552afa4cf533 (diff)
downloadgobject-introspection-9bf6ff0e49391c7aee76b2fcb6e479a34e19c058.tar.gz
Import CMPH 1.0
This will be used for typelib indexing. See README-CMPH-IMPORT.txt for more information.
Diffstat (limited to 'girepository/cmph/fnv_hash.c')
-rw-r--r--girepository/cmph/fnv_hash.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/girepository/cmph/fnv_hash.c b/girepository/cmph/fnv_hash.c
new file mode 100644
index 00000000..aeaca8ff
--- /dev/null
+++ b/girepository/cmph/fnv_hash.c
@@ -0,0 +1,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;
+}