From 41177ed32fe815545061f7d10ce13559f1e9eb98 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Sat, 27 Sep 2014 21:26:58 -0600 Subject: [PATCH] Add fnv hash Signed-off-by: Jens Axboe --- crc/fnv.c | 16 ++++++++++++++++ crc/fnv.h | 8 ++++++++ 2 files changed, 24 insertions(+) create mode 100644 crc/fnv.c create mode 100644 crc/fnv.h 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 + +uint64_t fnv(const void *, uint32_t, uint64_t); + +#endif -- 2.25.1