/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
- *
+ *
* HashKit library
*
* Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
#ifdef HAVE_MURMUR_HASH
+#ifdef BYTESWAP_HEADER
+# include BYTESWAP_HEADER
+#endif
+
#include <cstring>
uint32_t hashkit_murmur(const char *key, size_t length, void *context)
while(length >= 4)
{
- unsigned int k;
- memcpy(&k, data, sizeof(unsigned int));
+ uint32_t k;
+ memcpy(&k, data, sizeof(k));
+#if WORDS_BIGENDIAN
+ k = BYTESWAP_32(k);
+#endif
k *= m;
k ^= k >> r;
}
// Handle the last few bytes of the input array
-
- switch(length)
- {
- case 3: h ^= ((uint32_t)data[2]) << 16; /* fall through */
- case 2: h ^= ((uint32_t)data[1]) << 8; /* fall through */
- case 1: h ^= data[0];
- h *= m;
- default: break;
- };
+ if (length) {
+ uint32_t k = 0;
+ memcpy(&k, data, length);
+#if WORDS_BIGENDIAN
+ k = BYTESWAP_32(k);
+#endif
+ h ^= k;
+ h *= m;
+ }
/*
Do a few final mixes of the hash to ensure the last few bytes are