zoukankan      html  css  js  c++  java
  • javascript的hashCode实现

    hashCode = function(str){
        var hash = 0;
        if (str.length == 0) return hash;
        for (i = 0; i < str.length; i++) {
            char = str.charCodeAt(i);
            hash = ((hash<<5)-hash)+char;
            hash = hash & hash; // Convert to 32bit integer
        }
        return hash;
    }
    djb2Code = function(str){
        var hash = 5381;
        for (i = 0; i < str.length; i++) {
            char = str.charCodeAt(i);
            hash = ((hash << 5) + hash) + char; /* hash * 33 + c */
        }
        return hash;
    }
    sdbmCode = function(str){
        var hash = 0;
        for (i = 0; i < str.length; i++) {
            char = str.charCodeAt(i);
            hash = char + (hash << 6) + (hash << 16) - hash;
        }
        return hash;
    }
    loseCode = function(str){
        var hash = 0;
        for (i = 0; i < str.length; i++) {
            char = str.charCodeAt(i);
            hash += char;
        }
        return hash;
    }
  • 相关阅读:
    hdu1233
    zoj 3529
    hdu 2516 取石子游戏
    组合博弈理论
    博弈——sg函数的原理和优化
    博弈及sg函数
    poj2039
    hdu 1250
    C# 类的继承和访问
    C# 索引
  • 原文地址:https://www.cnblogs.com/pigtail/p/3342977.html
Copyright © 2011-2022 走看看