Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-03-16 13:27:25

Dave Harris wrote:
> In-Reply-To: <012301c5299e$0e2b2f90$6501a8c0_at_pdimov2>
> pdimov_at_[hidden] (Peter Dimov) wrote (abridged):
>> This is because you ignored the "use_a" member when computing the
>> hash value.
> I didn't ignore it; hash_value uses it, albeit not in the best way.
>> We can't prevent these mistakes in general; if you omit a member
>> (that affects the equivalence relation) when computing the hash
>> value, the computation is just wrong.
> In this case the computation was correct, and indeed carefully
> chosen, but produced needlessly many collisions.

OK, let's not talk in terms of "right" and "wrong".

Had you written your hash function following the guideline that every member
that is part of the state and affects the equivalence relation needs to be
hash_combined when computing the hash value, you'd not have had collisions.

In other words, making hash_value take into account the type of the member
is not necessary for writing good quality hash functions. It will only "fix"
some (questionably written) functions, but not all.

I do not dispute that writing good hash functions is hard; I just don't
agree that we should try to fix them from our side.

Boost list run by bdawes at, gregod at, cpdaniel at, john at