hash算法-time33算法

hash在开发中常常用到,而如今time33算是最流行的哈希算法。html

算法:对字符串的每一个字符,迭代的乘以33算法

原型:   hash(i) = hash(i-1)*33 + str[i] ;架构

在使用时,存在一个问题,对类似的字符串生成的hashcode也相似,有人提出对原始字符串,进行MD5,而后再计算hashcode。函数


最简单的版本:网站

uint32_t time33(char const *str, int len) 
    { 
        unsigned long  hash = 0; 
        for (int i = 0; i < len; i++) { 
            hash = hash *33 + (unsigned long) str[i]; 
        } 
        return hash; 
    }


参考文献:ui

《大型网站技术架构:核心原理与案例分析》spa

http://www.cnblogs.com/napoleon_liu/articles/1911571.html  time33 哈希函数,又叫 DJBX33A,Bernstein's hashcode

相关文章
相关标签/搜索