From: Michael Wallner Date: Tue, 13 Oct 2020 21:14:50 +0000 (+0200) Subject: attempt to fix murmur on big endian X-Git-Tag: 1.1.0-beta1~224 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=a7f20d24660e0569c372accbb112c2ffded81bbd;p=awesomized%2Flibmemcached attempt to fix murmur on big endian --- diff --git a/src/libhashkit/murmur.cc b/src/libhashkit/murmur.cc index a2ff5216..614b8a55 100644 --- a/src/libhashkit/murmur.cc +++ b/src/libhashkit/murmur.cc @@ -1,5 +1,5 @@ /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * + * * HashKit library * * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/ @@ -81,8 +81,16 @@ 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; +#if WORDS_BIGENDIAN + k = (data[0]<<24) + + (data[1]<<16) + + (data[2]<<8) + + (data[3]) + ; +#else + memcpy(&k, data, sizeof(k)); +#endif k *= m; k ^= k >> r; @@ -99,9 +107,15 @@ uint32_t hashkit_murmur(const char *key, size_t length, void *context) switch(length) { +#if WORDS_BIGENDIAN + case 3: h ^= ((uint32_t)data[2]) << 8; /* fall through */ + case 2: h ^= ((uint32_t)data[1]) << 16; /* fall through */ + case 1: h ^= ((uint32_t)data[0]) << 24; +#else 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]; +#endif h *= m; default: break; };