djb2 Hash Function

后端 未结 4 1738
暖寄归人
暖寄归人 2020-12-16 04:49

I am using the djb2 algorithm to generate the hash key for a string which is as follows

hash(unsigned char *str)
{
    unsigned long hash = 5381;
    int c;
         


        
4条回答
  •  情歌与酒
    2020-12-16 05:27

    Hash calculations often overflow. That's generally not a problem at all, so long as you have guarantees about what's going to happen when it does overflow. Don't forget that the point of a hash isn't to have a number which means something in terms of magniture etc - it's just a way of detecting equality. Why would overflow interfere with that?

提交回复
热议问题