]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
blobhash: Avoid size_t in templatized hash functions.
authorTommi Virtanen <tommi.virtanen@dreamhost.com>
Mon, 14 Mar 2011 18:52:44 +0000 (11:52 -0700)
committerSage Weil <sage@newdream.net>
Thu, 17 Mar 2011 18:59:26 +0000 (11:59 -0700)
On S/390, the earlier rjhash<size_t> failed with
"no match for call to '(rjhash<long unsigned int>) (size_t&)'".
It seems the rjhash<size_T> 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 <tommi.virtanen@dreamhost.com>
src/include/blobhash.h
src/include/hash.h

index 3544649e01969f19cfaa859ea92723a5c6dbab74..597884e4c9d82e706dc453aa992049c0becda5da 100644 (file)
 
 class blobhash {
 public:
-  size_t operator()(const char *p, unsigned len) {
-    static rjhash<size_t> 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<uint32_t> 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++;
index 2a1b6eb3ea9a724d419873a3ce3479c719691cba..2ab95448b51db8ebafa797808c02802b9ec11458 100644 (file)
@@ -57,19 +57,6 @@ template<> struct rjhash<uint64_t> {
   }
 };
 
-#if defined(__CYGWIN__) || defined(DARWIN)
-template<> struct rjhash<size_t> {
-  inline size_t operator()(const size_t x) const {
-#ifdef __LP64__
-    return rjhash64(x);
-#else
-    return rjhash32(x);
-#endif
-  }
-};
-#endif
-
-
 //}