summaryrefslogtreecommitdiff
path: root/utils/murmur_hash3.h
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-06-12 13:56:42 +0200
committerPatrick Simianer <p@simianer.de>2014-06-12 13:56:42 +0200
commit244971287003d079e46193b8a209c28955f90134 (patch)
tree8beaae6b12b913acb213fc7f2415fd63886192f9 /utils/murmur_hash3.h
parent5250fd67a4b8f242068cff87f0a6a4211f8b0fcf (diff)
parentb66e838ed52decc0be1eb5817b2a77c3840db2c5 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'utils/murmur_hash3.h')
-rw-r--r--utils/murmur_hash3.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/utils/murmur_hash3.h b/utils/murmur_hash3.h
new file mode 100644
index 00000000..a125d775
--- /dev/null
+++ b/utils/murmur_hash3.h
@@ -0,0 +1,67 @@
+//-----------------------------------------------------------------------------
+// MurmurHash3 was written by Austin Appleby, and is placed in the public
+// domain. The author hereby disclaims copyright to this source code.
+
+#ifndef _MURMURHASH3_H_
+#define _MURMURHASH3_H_
+
+//-----------------------------------------------------------------------------
+// Platform-specific functions and macros
+
+// Microsoft Visual Studio
+
+#if defined(_MSC_VER) && (_MSC_VER < 1600)
+
+typedef unsigned char uint8_t;
+typedef unsigned int uint32_t;
+typedef unsigned __int64 uint64_t;
+
+// Other compilers
+
+#else // defined(_MSC_VER)
+
+#include <stdint.h>
+
+#endif // !defined(_MSC_VER)
+
+//-----------------------------------------------------------------------------
+
+namespace cdec {
+
+void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out );
+
+void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out );
+
+void MurmurHash3_x64_128 ( const void * key, int len, uint32_t seed, void * out );
+
+namespace {
+ #ifdef __clang__
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wunused-function"
+ #endif
+ template <unsigned L> inline void cdecMurmurHashNativeBackend(const void * key, int len, uint32_t seed, void * out) {
+ MurmurHash3_x86_128(key, len, seed, out);
+ }
+ template <> inline void cdecMurmurHashNativeBackend<4>(const void * key, int len, uint32_t seed, void * out) {
+ MurmurHash3_x64_128(key, len, seed, out);
+ }
+ #ifdef __clang__
+ #pragma clang diagnostic pop
+ #endif
+} // namespace
+
+inline uint64_t MurmurHash3_64(const void * key, int len, uint32_t seed) {
+ uint64_t out[2];
+ cdecMurmurHashNativeBackend<sizeof(void*)>(key, len, seed, &out);
+ return out[0];
+}
+
+inline void MurmurHash3_128(const void * key, int len, uint32_t seed, void * out) {
+ cdecMurmurHashNativeBackend<sizeof(void*)>(key, len, seed, out);
+}
+
+}
+
+//-----------------------------------------------------------------------------
+
+#endif // _MURMURHASH3_H_