Boost logo

Boost :

Subject: Re: [boost] hash_combine vs hash_value
From: Michael Goldshteyn (mgoldshteyn_at_[hidden])
Date: 2011-03-25 11:32:47


The thing that bothers me about the use "hash_combine" for even the first
hashed value of a bunch of values is the fact that:

size_t myHashVal=0;

boost::hash_combine(myHashVal,firstVal);
...

becomes

size_t seed=0;
seed ^= hash_value(myFirstHashVal) + 0x9e3779b9; // + (seed << 6) + (seed >>
2) does nothing for seed==0
...

The xor'ing of the first value doesn't bother me, but this displacement by
0x9e3779b9 of the first value does, since for 32-bit size_t values, we've
just lost a bunch of info. It seems like the formula will result in less of
the first value being applied to the overall hash, due to the "potential"
unsigned 32-bit overflow caused by the addition. Maybe I'm misinterpreting
the effect. If so, please correct me.

Thanks,

Michael Goldshteyn
 


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk