mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 15:11:16 +08:00
Simplify PolynomialHash function.
This commit is contained in:
parent
51f496ce2e
commit
ff4854e0b8
@ -25,8 +25,7 @@ export default class PolynomialHash {
|
|||||||
let hash = 0;
|
let hash = 0;
|
||||||
for (let charIndex = 0; charIndex < charCodes.length; charIndex += 1) {
|
for (let charIndex = 0; charIndex < charCodes.length; charIndex += 1) {
|
||||||
hash *= this.base;
|
hash *= this.base;
|
||||||
hash %= this.modulus;
|
hash += charCodes[charIndex];
|
||||||
hash += charCodes[charIndex] % this.modulus;
|
|
||||||
hash %= this.modulus;
|
hash %= this.modulus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,11 +60,9 @@ export default class PolynomialHash {
|
|||||||
|
|
||||||
hash += this.modulus;
|
hash += this.modulus;
|
||||||
hash -= (prevValue * prevValueMultiplier) % this.modulus;
|
hash -= (prevValue * prevValueMultiplier) % this.modulus;
|
||||||
hash %= this.modulus;
|
|
||||||
|
|
||||||
hash *= this.base;
|
hash *= this.base;
|
||||||
hash %= this.modulus;
|
hash += newValue;
|
||||||
hash += newValue % this.modulus;
|
|
||||||
hash %= this.modulus;
|
hash %= this.modulus;
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
|
Loading…
Reference in New Issue
Block a user