
4 Oct
2011
4 Oct
'11
8:22 p.m.
On 4 October 2011 15:03, Tim Blechmann <tim@klingt.org> wrote:
inline std::size_t hash_value(int v) { return static_cast<std::size_t>(v); }
while this is probably the most efficient hash function, it is also the worst possible. is this done intentionally?
Why is this the "worst possible"? It never has any collisions (if sizeof(int) <= sizeof(size_t)), and typical use is mod-ing it with a prime number to determine the bucket for an unordered container. gcc also uses this for trivial hashes. -- Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404