xinglie / xinglie.github.io

blog
https://xinglie.github.io
153 stars 22 forks source link

js版BKDR哈希 #115

Open xinglie opened 9 months ago

xinglie commented 9 months ago
let hash = (str: string, seed = 131) => {//13,131,1313,13131,etc
    let hash = 0,
        i = 0,
        ch;
    while (i < str.length) {
        ch = str.charCodeAt(i++);
        hash = (seed * hash + ch) & 0x7FFFFFFF;
    }
    return hash;
};