Evolving Boost.ContainerHash
I've been thinking of updating and evolving Boost.ContainerHash, so I
e-mailed Daniel James to see what his thoughts on that are. He says he's
not going to come back to it, since he's moved on from C++. (Why would
anyone do so is beyond me. :-))
More specifically, what I'm envisaging is updating boost::hash to take a
seed:
template<class T> struct hash
{
hash(); // as before
explicit hash( size_t seed );
size_t operator()(T const& v)
{
return detail::hash_combine(seed, hash_value(v));
}
};
The public hash_combine then becomes:
template<class T> void hash_combine( size_t& seed, T const& v )
{
return hash<T>(seed)(v);
}
This allows passing seeded hashes to unordered containers, without
any changes to the latter:
std::unordered_map
On Tue, Oct 12, 2021 at 4:26 PM Peter Dimov via Boost
template<class T> void hash_combine( size_t& seed, T const& v )
In principle it sounds like an improvement, but what about the paper "Types Don't Know #?" (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3980.html) The paper shows empirical evidence that hash_combine has poor collision properties when composing hash functions.
I also think that Boost.ContainerHash should just be renamed to Boost.Hash as that's what it is - it defines boost::hash.
So, I am thinking of taking over ContainerHash and doing all that, if there are no objections.
What happens with hash_append from the paper? Thanks
Vinnie Falco wrote:
On Tue, Oct 12, 2021 at 4:26 PM Peter Dimov via Boost
wrote: template<class T> void hash_combine( size_t& seed, T const& v )
In principle it sounds like an improvement, but what about the paper "Types Don't Know #?" (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3980.html)
The paper shows empirical evidence that hash_combine has poor collision properties when composing hash functions.
...
What happens with hash_append from the paper?
As you well know, what happens with hash_append from the paper is that it has been sitting in https://github.com/pdimov/hash2 for years now while I was promising to finish the library and submit it to Boost. I'm still doing that. (Promising, I mean.)
On Tue, Oct 12, 2021 at 4:46 PM Peter Dimov
As you well know, what happens with hash_append from the paper is that it has been sitting in https://github.com/pdimov/hash2 for years now
Ok, so Hash2 is in addition to and not in lieu of Boost.ContainerHash (or Boost.Hash). I'm thinking optimistically that evolving Boost.ContainerHash will inspire you to move Hash2 forward :) Thanks
participants (2)
-
Peter Dimov
-
Vinnie Falco