summaryrefslogtreecommitdiff
path: root/fnv.c
diff options
context:
space:
mode:
Diffstat (limited to 'fnv.c')
-rw-r--r--fnv.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/fnv.c b/fnv.c
new file mode 100644
index 0000000..af6532c
--- /dev/null
+++ b/fnv.c
@@ -0,0 +1,26 @@
+#include <stdlib.h>
+#include <stdint.h>
+
+uint64_t fnv1_64(const void *src, size_t len)
+{
+ const unsigned char *d = (const unsigned char *)src;
+ uint64_t h = 0xcbf29ce484222325;
+ size_t i;
+ for (i = 0; i < len; i++) {
+ h *= 0x100000001b3;
+ h ^= d[i];
+ }
+ return h;
+}
+
+uint64_t fnv1a_64(const void *src, size_t len)
+{
+ const unsigned char *d = (const unsigned char *)src;
+ uint64_t h = 0xcbf29ce484222325;
+ size_t i;
+ for (i = 0; i < len; i++) {
+ h ^= d[i];
+ h *= 0x100000001b3;
+ }
+ return h;
+}