mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-25 22:46:20 +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;
|
||||
for (let charIndex = 0; charIndex < charCodes.length; charIndex += 1) {
|
||||
hash *= this.base;
|
||||
hash %= this.modulus;
|
||||
hash += charCodes[charIndex] % this.modulus;
|
||||
hash += charCodes[charIndex];
|
||||
hash %= this.modulus;
|
||||
}
|
||||
|
||||
@ -61,11 +60,9 @@ export default class PolynomialHash {
|
||||
|
||||
hash += this.modulus;
|
||||
hash -= (prevValue * prevValueMultiplier) % this.modulus;
|
||||
hash %= this.modulus;
|
||||
|
||||
hash *= this.base;
|
||||
hash %= this.modulus;
|
||||
hash += newValue % this.modulus;
|
||||
hash += newValue;
|
||||
hash %= this.modulus;
|
||||
|
||||
return hash;
|
||||
|
Loading…
Reference in New Issue
Block a user