//此处只是获得了字符串的hash值,但是该如何散列到hash表中呢?哪个算法会好些?! 1 //在处理以字符串为键值的哈希时,times33哈希算法有着极快的计算效率和很好的哈希分布 2 3 //小写英文单词 4 #if 1 5 unsigned int str_hash(const char* key) 6 { 7 unsigned int hashval = 0; 8 while(*key) 9 {10 hash = ((hash << 5) + hash) + (unsigned int)*key++;11 }12 13 return hash;14 }15 16 #else17 18 unsigned int str_has(const char* key)19 {20 unsigned int hashval = 0;21 while(*key)22 {23 hash = (hash << 7 + hash) + (unsigned int)*key++;24 }25 26 return hash;27 }28 29 #endif