summaryrefslogtreecommitdiff
path: root/crc
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2014-09-27 21:26:58 -0600
committerJens Axboe <axboe@fb.com>2014-09-27 21:26:58 -0600
commit41177ed32fe815545061f7d10ce13559f1e9eb98 (patch)
tree0e9cbeedeb8151fbee40d5b7e8e4bfbf6a5a31d8 /crc
parent9c8566f54872a2cff2b453438f9590e4c6582654 (diff)
downloadfio-41177ed32fe815545061f7d10ce13559f1e9eb98.tar.gz
fio-41177ed32fe815545061f7d10ce13559f1e9eb98.tar.bz2
Add fnv hash
Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'crc')
-rw-r--r--crc/fnv.c16
-rw-r--r--crc/fnv.h8
2 files changed, 24 insertions, 0 deletions
diff --git a/crc/fnv.c b/crc/fnv.c
new file mode 100644
index 00000000..04c0560c
--- /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
index 00000000..ef2b77b4
--- /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