www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - A detail of the hash protocol

reply bearophile <bearophileHUGS lycos.com> writes:
In this page:
http://www.digitalmars.com/d/1.0/arrays.html#associative
regarding the hashing protocol it says that structs need:
uint toHash();
While classes:
hash_t toHash()

Is that a little documentation error? I presume they both have to return an
uint or hash_t or a size_t...

What's the purpose of a separated hash_t type? Can't it be removed, keeping
just an uint or size_t for that purpose?

Thank you, bye,
bearophile
Oct 25 2008
next sibling parent ore-sama <spam here.lot> writes:
bearophile Wrote:

 What's the purpose of a separated hash_t type? Can't it be removed, keeping
just an uint or size_t for that purpose?

there are different hash algorithms, so hash_t is not forced to be size_t.
Oct 25 2008
prev sibling parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Sat, Oct 25, 2008 at 4:20 AM, bearophile <bearophileHUGS lycos.com> wrote:
 In this page:
 http://www.digitalmars.com/d/1.0/arrays.html#associative
 regarding the hashing protocol it says that structs need:
 uint toHash();
 While classes:
 hash_t toHash()

 Is that a little documentation error? I presume they both have to return an
uint or hash_t or a size_t...

 What's the purpose of a separated hash_t type? Can't it be removed, keeping
just an uint or size_t for that purpose?

 Thank you, bye,
 bearophile

I'm pretty sure it's actually a limitation of DDoc. DDoc always outputs the base type of an alias instead of the alias name, which really, _really_ pisses me off. Coincidentally, hash_t is defined as "alias uint hash_t;", I presume for the potential of having i.e. a 64-bit hash at some point.
Oct 25 2008