diff --git a/src/hash/hash.c b/src/hash/hash.c index 59476f9..b90c959 100644 --- a/src/hash/hash.c +++ b/src/hash/hash.c @@ -1,8 +1,8 @@ #include "hash.h" /*两个计算哈希值的哈希函数*/ -int hash_func1(const char *key); -int hash_func2(const char *key); +unsigned int hash_func1(const char *key); +unsigned int hash_func2(const char *key); int conf_value_insert(CONF_ARG *arg) { @@ -15,7 +15,7 @@ CONF_VALUE **conf_value_get_all(CONF *conf) {} /*BKDR 哈希算法*/ -int hash_func1(const char *key) +unsigned int hash_func1(const char *key) { unsigned int seed=131; unsigned int hash=0; @@ -30,23 +30,21 @@ int hash_func1(const char *key) return hash&0x7FFFFFFF; } -/*AP 哈希算法*/ -int hash_func2(const char *key) +/*ELF 哈希算法*/ +unsigned int hash_func2(const char *key) { unsigned int hash=0; - int i; + unsigned int x=0; - for(i=0;key[i];++i) + while(*key) { - if((i & 1) == 0) + hash=(hash << 4)+*key; + ++key; + + if((x = hash & 0xF0000000L) != 0) { - hash^=((hash << 7)^*key^(hash >> 3)); - ++key; - } - else - { - hash^=(~((hash << 11)^*key^(hash >> 5))); - ++key; + hash^=(x>>24); + hash&=~x; } }