Re: [boost] Re: [review] hash functions

In-Reply-To: <d1on4o$ijr$1@sea.gmane.org> daniel@calamity.org.uk (Daniel James) wrote (abridged):
Admittedly hash_combine is also (nearly) redundant, being definable as:
void hash_combine( size_t &hash, const T &t ) { hash_range( hash, &t, &t+1 ); }
if T does not overload address-of.
Note this is currently true because hash_range is defined as having the effect of: void hash_range( size_t &hash, It first, It last ) { for (; first != last; ++first) hash_combine( hash, *first ); } so calling hash_range on a range of 1 element returns the same result as calling hash_combine with that element.
Since nested vectors give different hash values to their flattened form, I don't think a single element vector should have the same hash values as it's element.
It doesn't. One is: return hash_value( t ); the other is: size_t hash = 0; hash_combine( hash, t ); return hash; All the proposed definitions of hash_combine make these different. There is at least an xor, and possible a constant added. -- Dave Harris, Nottingham, UK

Dave Harris wrote:
In-Reply-To: <d1on4o$ijr$1@sea.gmane.org> daniel@calamity.org.uk (Daniel James) wrote (abridged):
Admittedly hash_combine is also (nearly) redundant, being definable as:
void hash_combine( size_t &hash, const T &t ) { hash_range( hash, &t, &t+1 ); }
if T does not overload address-of.
Note this is currently true because hash_range is defined as having the effect of:
void hash_range( size_t &hash, It first, It last ) { for (; first != last; ++first) hash_combine( hash, *first ); }
so calling hash_range on a range of 1 element returns the same result as calling hash_combine with that element.
Sorry, I misread what you were saying. I shouldn't have rushed of an answer before going to work. Everything I wrote still stands, but I suppose the response to that part was irrelevant. Daniel
participants (2)
-
brangdon@cix.compulink.co.uk
-
Daniel James