Re: hash_map
tat wrote:
Hi all,
Thanks very much for all of your comments about hash_map and various
issues around it.
Can someone suggest a good string hash function for a string of length
ranging from 7 to 13?
This one works well for me:
size_t hash(char const* p)
{
size_t r = 0;
// 31 is an empirical value obtained from hashing real logins
// 6291469 buckets
// 4142516 logins
// 894278 collisions
// 8 max bucket size
for(;*p; ++p)
r = r * 31 + *p;
return r;
}
I googled and found a webpage
(GeneralHashFunctions) of Arash Partow (http://www.partow.net) on which
there are a number of hash functions. I copied them below. I am not
sure which one is good for my case.
Can you profile it for your particular application to see which one
suits you needs best?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]