From: Tommi Virtanen Date: Mon, 14 Mar 2011 18:52:44 +0000 (-0700) Subject: blobhash: Avoid size_t in templatized hash functions. X-Git-Tag: v0.26~106 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=68a2f46f23deaa03a60c1ddba90e1d27760382a5;p=ceph.git blobhash: Avoid size_t in templatized hash functions. On S/390, the earlier rjhash failed with "no match for call to '(rjhash) (size_t&)'". It seems the rjhash logic was only enabled on some architectures, and relied on some pretty deep internals of the bit layout (__LP64__). Use an explicitly 32-bit type as early as possible, and convert back to size_t only when really needed. This should work, and simplifies the code. In theory, we might have a narrower output (size_t might be 64-bit, max value we now output is 32-bit), but this doesn't matter as this is only ever used for picking a slot in an in-memory hash table, hash(key) modulo num_of_buckets, there won't be >4G buckets. Closes: #837 Signed-off-by: Tommi Virtanen --- diff --git a/src/include/blobhash.h b/src/include/blobhash.h index 3544649e01969..597884e4c9d82 100644 --- a/src/include/blobhash.h +++ b/src/include/blobhash.h @@ -24,17 +24,17 @@ class blobhash { public: - size_t operator()(const char *p, unsigned len) { - static rjhash H; - size_t acc = 0; - while (len >= sizeof(size_t)) { - acc ^= *(size_t*)p; - p += sizeof(size_t); - len -= sizeof(size_t); - } + uint32_t operator()(const char *p, unsigned len) { + static rjhash H; + uint32_t acc = 0; + while (len >= sizeof(acc)) { + acc ^= *(uint32_t*)p; + p += sizeof(uint32_t); + len -= sizeof(uint32_t); + } int sh = 0; while (len) { - acc ^= (size_t)*p << sh; + acc ^= (uint32_t)*p << sh; sh += 8; len--; p++; diff --git a/src/include/hash.h b/src/include/hash.h index 2a1b6eb3ea9a7..2ab95448b51db 100644 --- a/src/include/hash.h +++ b/src/include/hash.h @@ -57,19 +57,6 @@ template<> struct rjhash { } }; -#if defined(__CYGWIN__) || defined(DARWIN) -template<> struct rjhash { - inline size_t operator()(const size_t x) const { -#ifdef __LP64__ - return rjhash64(x); -#else - return rjhash32(x); -#endif - } -}; -#endif - - //}