projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
testing
[awesomized/libmemcached]
/
src
/
libhashkit
/
murmur.cc
diff --git
a/src/libhashkit/murmur.cc
b/src/libhashkit/murmur.cc
index f3e8fe6ac7eebcca2d92d72e69d19e249aed2934..c1451639c57a67a069683892e4f5972f24f1262c 100644
(file)
--- a/
src/libhashkit/murmur.cc
+++ b/
src/libhashkit/murmur.cc
@@
-1,5
+1,5
@@
/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
- *
+ *
* HashKit library
*
* Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
* HashKit library
*
* Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
@@
-52,10
+52,14
@@
Updated to murmur2 hash - BP
*/
Updated to murmur2 hash - BP
*/
-#include
<libhashkit/common.h>
+#include
"libhashkit/common.h"
#ifdef HAVE_MURMUR_HASH
#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)
#include <cstring>
uint32_t hashkit_murmur(const char *key, size_t length, void *context)
@@
-81,8
+85,11
@@
uint32_t hashkit_murmur(const char *key, size_t length, void *context)
while(length >= 4)
{
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;
k *= m;
k ^= k >> r;
@@
-96,15
+103,15
@@
uint32_t hashkit_murmur(const char *key, size_t length, void *context)
}
// Handle the last few bytes of the input array
}
// 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
/*
Do a few final mixes of the hash to ensure the last few bytes are