From ff4854e0b8f2b905d75a12c2c73309d0c05a7663 Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Thu, 9 Aug 2018 16:04:59 +0300 Subject: [PATCH] Simplify PolynomialHash function. --- .../cryptography/polynomial-hash/PolynomialHash.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/algorithms/cryptography/polynomial-hash/PolynomialHash.js b/src/algorithms/cryptography/polynomial-hash/PolynomialHash.js index 858faab9..ba066c31 100644 --- a/src/algorithms/cryptography/polynomial-hash/PolynomialHash.js +++ b/src/algorithms/cryptography/polynomial-hash/PolynomialHash.js @@ -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;