Thread overview
Flexible and efficient recursive hashing
Sep 16, 2014
bearophile
Sep 17, 2014
Szymon Gatner
Sep 17, 2014
H. S. Teoh
Sep 17, 2014
Sean Kelly
September 16, 2014
Among the CppCon 2014 slide packs there is this nice one:

"Types Don't Know #", by Howard Hinnant:

https://github.com/CppCon/CppCon2014/tree/master/Presentations/Types%20Don%27t%20Know%20%23%20-%20Howard%20Hinnant%20-%20CppCon%202014

It shows a nice idea to perform transitive hashing in a flexible and efficient way. Perhaps the idea can be used in D too. It suggests the introduction of a hashAppend standard method.

Bye,
bearophile
September 17, 2014
On Tuesday, 16 September 2014 at 14:53:52 UTC, bearophile wrote:
> Among the CppCon 2014 slide packs there is this nice one:
>
> "Types Don't Know #", by Howard Hinnant:
>
> https://github.com/CppCon/CppCon2014/tree/master/Presentations/Types%20Don%27t%20Know%20%23%20-%20Howard%20Hinnant%20-%20CppCon%202014
>
> It shows a nice idea to perform transitive hashing in a flexible and efficient way. Perhaps the idea can be used in D too. It suggests the introduction of a hashAppend standard method.
>
> Bye,
> bearophile

Funny thing is that as soon as you have to combine hashes in C++ atm you realize that current way is broken and the way HH proposes is kindof obvious correct design.
September 17, 2014
On Tue, Sep 16, 2014 at 02:53:51PM +0000, bearophile via Digitalmars-d wrote:
> Among the CppCon 2014 slide packs there is this nice one:
> 
> "Types Don't Know #", by Howard Hinnant:
> 
> https://github.com/CppCon/CppCon2014/tree/master/Presentations/Types%20Don%27t%20Know%20%23%20-%20Howard%20Hinnant%20-%20CppCon%202014
> 
> It shows a nice idea to perform transitive hashing in a flexible and efficient way. Perhaps the idea can be used in D too. It suggests the introduction of a hashAppend standard method.
[...]

This is all the more reason to make rt.util.hash.hashOf available to user code. It already supports chaining, which would be the equivalent of hashAppend.


T

-- 
The computer is only a tool. Unfortunately, so is the user. -- Armaphine, K5
September 17, 2014
On Tuesday, 16 September 2014 at 14:53:52 UTC, bearophile wrote:
> Among the CppCon 2014 slide packs there is this nice one:
>
> "Types Don't Know #", by Howard Hinnant:
>
> https://github.com/CppCon/CppCon2014/tree/master/Presentations/Types%20Don%27t%20Know%20%23%20-%20Howard%20Hinnant%20-%20CppCon%202014
>
> It shows a nice idea to perform transitive hashing in a flexible and efficient way. Perhaps the idea can be used in D too. It suggests the introduction of a hashAppend standard method.

Yes, I've never understood why std::hash was designed the way it
is.  Or why allowing the user to supply a seed value seems to be
unusual for publicly available hash routines (which is basically
what Howard has proposed).  rt.util.hash.hashOf accepts a seed
value, and any hash routine we made publicly callable should as
well.  Not to do so is really pretty useless.

I guess this also has implications for composite types in D.  If
I have a class that references other classes, I might want to do
the same basic thing.  In which case, calling Object.toHash isn't
sufficient as it fails in the same manner.  I suppose we really
need to extend toHash to accept an optional seed value as well.