Add fnv hash
authorJens Axboe <axboe@fb.com>
Sun, 28 Sep 2014 03:26:58 +0000 (21:26 -0600)
committerJens Axboe <axboe@fb.com>
Sun, 28 Sep 2014 03:26:58 +0000 (21:26 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
crc/fnv.c [new file with mode: 0644]
crc/fnv.h [new file with mode: 0644]

diff --git a/crc/fnv.c b/crc/fnv.c
new file mode 100644 (file)
index 0000000..04c0560
--- /dev/null
+++ b/crc/fnv.c
@@ -0,0 +1,16 @@
+#include "fnv.h"
+
+#define FNV_PRIME      0x100000001b3ULL
+
+uint64_t fnv(const void *buf, uint32_t len, uint64_t hval)
+{
+       const uint64_t *ptr = buf;
+       const uint64_t *end = (void *) buf + len;
+
+       while (ptr < end) {
+               hval *= FNV_PRIME;
+               hval ^= (uint64_t) *ptr++;
+       }
+
+       return hval;
+}
diff --git a/crc/fnv.h b/crc/fnv.h
new file mode 100644 (file)
index 0000000..ef2b77b
--- /dev/null
+++ b/crc/fnv.h
@@ -0,0 +1,8 @@
+#ifndef FIO_FNV_H
+#define FIO_FNV_H
+
+#include <inttypes.h>
+
+uint64_t fnv(const void *, uint32_t, uint64_t);
+
+#endif