better? hash, sdbm

This commit is contained in:
p.kosyh 2011-04-06 10:23:34 +00:00
parent 7bf4c9e577
commit 5e8ab6e3e6

View file

@ -36,16 +36,13 @@ static unsigned long hash_addr(void *p)
{ {
return (long)p; return (long)p;
} }
static unsigned long hash_string(const char *str) static unsigned long hash_string(const char *str)
{ {
unsigned long hash = 0; unsigned long hash = 0;
int i; int c;
int len = strlen(str); while ((c = *str++))
for (i = 0; i < len; i++) { hash = c + (hash << 6) + (hash << 16) - hash;
hash = (hash << 7) | (hash >> (sizeof(hash)*8 - 7));
hash ^= str[i]; /* GOLDEN_RATIO_PRIME_32; */
}
// fprintf(stderr, "%d\n", hash % HASH_SIZE);
return hash; return hash;
} }