Time33哈希算法

Time33哈希算法算法

算法:對字符串的每一個字符,迭代的乘以33ui

公式:   hash(i) = hash(i-1)*33 + str[i] ;spa

在使用時,存在一個問題,對類似的字符串生成的hashcode也相似,code

能夠對原始字符串,進行MD5,再hashcode。orm

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; 
    }
相關文章
相關標籤/搜索