summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fnv_hash.c15
-rw-r--r--fnv_hash.h1
2 files changed, 16 insertions, 0 deletions
diff --git a/fnv_hash.c b/fnv_hash.c
index 870dc0d..99801ce 100644
--- a/fnv_hash.c
+++ b/fnv_hash.c
@@ -50,6 +50,21 @@ fnv1_hash_string(const char *key)
return hash;
}
+uint32_t
+fnv1_hash_data(const void *data, size_t size)
+{
+ uint32_t hash = 2166136261ul;
+ const uint8_t *bytes = (uint8_t *)data;
+
+ while (size-- != 0) {
+ hash ^= *bytes;
+ hash = hash * 0x01000193;
+ bytes++;
+ }
+
+ return hash;
+}
+
int
string_key_equals(const void *a, const void *b)
{
diff --git a/fnv_hash.h b/fnv_hash.h
index 12ced2d..eb98205 100644
--- a/fnv_hash.h
+++ b/fnv_hash.h
@@ -31,4 +31,5 @@
#include <inttypes.h>
uint32_t fnv1_hash_string(const char *key);
+uint32_t fnv1_hash_data(const void *data, size_t size);
int string_key_equals(const void *a, const void *b);