Subject: Re: [boost] [functional/hash] integer hash function
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-10-04 18:19:25
On 10/04/2011 10:03 PM, Tim Blechmann wrote:
> i was quite amazed that the default hash function for integers seems to be the
> identity function:
> from boost/functional/hash/hash.hpp:
> inline std::size_t hash_value(int v)
> return static_cast<std::size_t>(v);
> while this is probably the most efficient hash function, it is also the worst
> possible. is this done intentionally?
It's only bad if you know your possible values are not equally
distributed over the whole range of "int".
Which is not something a default hashing function can know.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk