From 5e8ab6e3e653acaf4b071301c217b3419a495096 Mon Sep 17 00:00:00 2001 From: "p.kosyh" Date: Wed, 6 Apr 2011 10:23:34 +0000 Subject: [PATCH] better? hash, sdbm --- src/sdl-instead/cache.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/sdl-instead/cache.c b/src/sdl-instead/cache.c index 48a4af5..492fd60 100644 --- a/src/sdl-instead/cache.c +++ b/src/sdl-instead/cache.c @@ -36,16 +36,13 @@ static unsigned long hash_addr(void *p) { return (long)p; } + static unsigned long hash_string(const char *str) { unsigned long hash = 0; - int i; - int len = strlen(str); - for (i = 0; i < len; i++) { - hash = (hash << 7) | (hash >> (sizeof(hash)*8 - 7)); - hash ^= str[i]; /* GOLDEN_RATIO_PRIME_32; */ - } -// fprintf(stderr, "%d\n", hash % HASH_SIZE); + int c; + while ((c = *str++)) + hash = c + (hash << 6) + (hash << 16) - hash; return hash; }