mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
Merge 7615da1040
into ca3d16dcce
This commit is contained in:
commit
109be25075
@ -21,12 +21,12 @@ describe('PolynomialHash', () => {
|
||||
|
||||
// Check hashing for different word lengths.
|
||||
frameSizes.forEach((frameSize) => {
|
||||
let previousWord = text.substr(0, frameSize);
|
||||
let previousWord = text.slice(0, frameSize);
|
||||
let previousHash = polynomialHash.hash(previousWord);
|
||||
|
||||
// Shift frame through the whole text.
|
||||
for (let frameShift = 1; frameShift < (text.length - frameSize); frameShift += 1) {
|
||||
const currentWord = text.substr(frameShift, frameSize);
|
||||
const currentWord = text.slice(frameShift, frameShift + frameSize);
|
||||
const currentHash = polynomialHash.hash(currentWord);
|
||||
const currentRollingHash = polynomialHash.roll(previousHash, previousWord, currentWord);
|
||||
|
||||
|
@ -18,12 +18,12 @@ describe('PolynomialHash', () => {
|
||||
|
||||
// Check hashing for different word lengths.
|
||||
frameSizes.forEach((frameSize) => {
|
||||
let previousWord = text.substr(0, frameSize);
|
||||
let previousWord = text.slice(0, frameSize);
|
||||
let previousHash = polynomialHash.hash(previousWord);
|
||||
|
||||
// Shift frame through the whole text.
|
||||
for (let frameShift = 1; frameShift < (text.length - frameSize); frameShift += 1) {
|
||||
const currentWord = text.substr(frameShift, frameSize);
|
||||
const currentWord = text.slice(frameShift, frameShift + frameSize);
|
||||
const currentHash = polynomialHash.hash(currentWord);
|
||||
const currentRollingHash = polynomialHash.roll(previousHash, previousWord, currentWord);
|
||||
|
||||
|
@ -32,7 +32,7 @@ export default function rabinKarp(text, word) {
|
||||
// In case of hash collision the strings may not be equal.
|
||||
if (
|
||||
wordHash === currentFrameHash
|
||||
&& text.substr(charIndex, word.length) === word
|
||||
&& text.slice(charIndex, charIndex + word.length) === word
|
||||
) {
|
||||
return charIndex;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user