Reduce hash value collision probability in src/main.c

Original code use "hash_value = *name++", which may produce
hash value collision for word permutations like "abc", "bac" and "cba".
This commit is contained in:
Homer Hsing 2012-09-14 10:06:39 +08:00 committed by Damien Lespiau
parent 940522588a
commit 7186723f81

View File

@ -78,10 +78,10 @@ static void usage(void)
static int hash(char *name) static int hash(char *name)
{ {
int ret = 0; unsigned ret = 0;
while(*name) while(*name)
ret += *name++; ret = (ret << 1) + (*name++);
return ret%HASHSZ; return ret % HASHSZ;
} }
struct declared_register *find_register(char *name) struct declared_register *find_register(char *name)