changed djb2 to xor version

This commit is contained in:
wangyu 2017-08-05 17:58:41 +08:00
parent 9542e37577
commit 7bd2fa7ab8

View File

@ -57,7 +57,7 @@ unsigned int crc32h(unsigned char *message,int len) {
return ; return ;
}*/ }*/
void simple_hash(unsigned char *str,int len,unsigned char* res) //djb2+ sdbm void simple_hash(unsigned char *str,int len,unsigned char res[8]) //djb2+ sdbm
{ {
u32_t hash = 5381; u32_t hash = 5381;
u32_t hash2 = 0; u32_t hash2 = 0;
@ -65,7 +65,8 @@ void simple_hash(unsigned char *str,int len,unsigned char* res) //djb2+ sdbm
int i=0; int i=0;
while(c = *str++,i++!=len) while(c = *str++,i++!=len)
{ {
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ // hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
hash = ((hash << 5) + hash)^c; /* (hash * 33) ^ c */
hash2 = c + (hash2 << 6) + (hash2 << 16) - hash2; hash2 = c + (hash2 << 6) + (hash2 << 16) - hash2;
} }