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>
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++;
}
};
-#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
-
-
//}