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;
}
上一篇:深度学习阅读列表 Deep Learning Reading List


下一篇:C# Winform关于控件TabControl闪烁的问题