[hash] hash returning fixed width integer instead of size_t?
I would like this code return the same hash on different machines:
#include <iostream>
#include
2011/5/20 Frédéric Bron
But I get 1244709680 when size_t is 32 bits and 706246339511088 when size_t is 64 bits. Is it possible to have hash work with fixed width uint32_t instead of size_t?
No sorry it isn't. If you're just hashing strings, you might want to try the 32 bit version of murmurhash3: http://code.google.com/p/smhasher/wiki/MurmurHash3
No sorry it isn't. If you're just hashing strings, you might want to try the 32 bit version of murmurhash3:
No I am hashing strings and double so I have copied the boost code and replaced size_t by boost::uint32_t. Works fine. The hash type could be a template parameter, couldn't it? Frédéric
2011/5/20 Frédéric Bron
No sorry it isn't. If you're just hashing strings, you might want to try the 32 bit version of murmurhash3:
No I am hashing strings and double so I have copied the boost code and replaced size_t by boost::uint32_t. Works fine. The hash type could be a template parameter, couldn't it?
Not really, since the hashing is done by 'hash_value' which can be user defined. I'm not sure if this is a good idea, but I could use another parameter to specify the hash type. Might have odd consequences for ADL. Something like: // Default to using the std::size_t version. template < typename T, typename HashType> HashType hash_value(T const& value, HashType*) { return hash_value(value); } template <typename HashType> HashType hash_value(double value, HashType* hash_type) { return boost::hash_detail::float_hash_value(value, hash_type); } template <typename HashType> HashType hash_value(long value, HashType*) { return static_cast<HashType>(value); } // etc.
participants (2)
-
Daniel James
-
Frédéric Bron