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

相關文章
相關標籤/搜索