diff options
-rw-r--r-- | fnv_hash.c | 15 | ||||
-rw-r--r-- | fnv_hash.h | 1 |
2 files changed, 16 insertions, 0 deletions
@@ -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) { @@ -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); |