下面的哈希函数与标准的哈希有些不一样,有需要的可以拿去用
C版本的hash

#javaScript的Hash
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| hashCode: function(str) {
var bin_code = new Uint32Array(); var offset = new Uint8Array(); let k = strToHexCharCode(str[0]); offset = k & 0x3F; offset = offset % (str.length - 5); bin_code = (strToHexCharCode(str[offset]) & 0x7f) << 24 | (strToHexCharCode(str[offset + 1]) & 0xff) << 16 | (strToHexCharCode(str[offset + 2]) & 0xff) << 8 | (strToHexCharCode(str[offset + 3]) & 0xff);
let sss = Math.pow(10, 6);
bin_code = bin_code % sss;
return bin_code; },
function strToHexCharCode(str) { if (str === "") return ""; var hexCharCode = []; hexCharCode.push("0x"); for (var i = 0; i < str.length; i++) { hexCharCode.push((str.charCodeAt(i)).toString(16)); } return hexCharCode.join(""); }
|