
20 Mar
2006
20 Mar
'06
9:36 p.m.
Daniel James wrote:
The integer hashes are defined as:
std::size_t hash_value(val) { return val; }
This is fine for most types, but since long long typically has a much larger range of values than std::size_t, it will work very badly for long long.
For larger integer types, we probably need something along the lines of std::size_t hash_value( val ) { size_t r = val; while( val >>= size_t_bits ) { hash_combine( r, (size_t)val ); } return r; } It has the property of preserving the hash_value of all _values_ that can fit into a size_t, even though the underlying type is capable of holding bigger integers.