|
Boost Users : |
Subject: Re: [Boost-users] [hash] hash returning fixed width integer instead of size_t?
From: Daniel James (dnljms_at_[hidden])
Date: 2011-05-20 09:50:03
2011/5/20 Frédéric Bron <frederic.bron_at_[hidden]>:
>> 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.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net