Skip to content

Commit ff4854e

Browse files
committedAug 9, 2018
Simplify PolynomialHash function.
1 parent 51f496c commit ff4854e

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed
 

‎src/algorithms/cryptography/polynomial-hash/PolynomialHash.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export default class PolynomialHash {
2525
let hash = 0;
2626
for (let charIndex = 0; charIndex < charCodes.length; charIndex += 1) {
2727
hash *= this.base;
28-
hash %= this.modulus;
29-
hash += charCodes[charIndex] % this.modulus;
28+
hash += charCodes[charIndex];
3029
hash %= this.modulus;
3130
}
3231

@@ -61,11 +60,9 @@ export default class PolynomialHash {
6160

6261
hash += this.modulus;
6362
hash -= (prevValue * prevValueMultiplier) % this.modulus;
64-
hash %= this.modulus;
6563

6664
hash *= this.base;
67-
hash %= this.modulus;
68-
hash += newValue % this.modulus;
65+
hash += newValue;
6966
hash %= this.modulus;
7067

7168
return hash;

0 commit comments

Comments
 (0)
Please sign in to comment.