|
|
|
|
|
by unwind
5348 days ago
|
|
Whoa. That file contained the absolutely most naive string hash function I've ever seen: static int get_string_hash(const char *s)
{
int val = 0;
if (s == NULL)
return val;
while (*s)
val += *s++;
return val & ALISP_OBJ_PAIR_HASH_MASK;
}
It seems to cleverly avoid everything that's supposed to go into a string hash function, and makes me quite wary of the rest of the file's code quality. I stopped reading after checking that this function is indeed used (it is).Also, the file itself was last modified on 2011-10-18, which seems to be pretty recent for something that's not used. Perhaps they're gearing up to start using it, and if that's going to involve any kind of even remotely performance-sensitive, I hope they replace the hash function first. :) |
|
The biggest problem I see with this hash function is that it will produce very many collisions (because most common strings will probably produce only small numbers).
I have seen other very simple string hash functions which just take the 4 first bytes (or 4 last or some sort of other pattern) of the string and use them (interpreted as 32bit integer) as the hash.