-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚴 perf: Scan middle snake only once.
Fixes #19.
- Loading branch information
1 parent
6c6413d
commit da6d7e5
Showing
6 changed files
with
100 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import assert from 'assert'; | ||
|
||
import bound from './bound.js'; | ||
import longestCommonSuffix from './longestCommonSuffix.js'; | ||
/** | ||
* Diagonal backward extension without yield. | ||
* | ||
* @param {number} center | ||
* @param {number} D | ||
* @param {Int32Array} V | ||
* @param {Function} eq | ||
* @param {number} li | ||
* @param {number} lj | ||
* @param {number} ri | ||
* @param {number} rj | ||
* @param {number} Delta | ||
*/ | ||
export default function backwardExtend( | ||
center, | ||
D, | ||
V, | ||
eq, | ||
li, | ||
lj, | ||
ri, | ||
rj, | ||
Delta, | ||
) { | ||
assert(ri > rj && li > lj); | ||
// NOTE: We make the bounding box as small as possible. | ||
// This should save roughly half of the computation time compared to | ||
// letting LB = -D and UB = D. | ||
const LB = -bound(D, li - lj); | ||
const UB = bound(D, ri - rj); | ||
assert(LB <= UB); | ||
assert(LB !== D); | ||
assert(UB !== -D); | ||
|
||
console.debug('beg backwardExtend', { | ||
center, | ||
D, | ||
V, | ||
eq, | ||
li, | ||
lj, | ||
ri, | ||
rj, | ||
LB, | ||
UB, | ||
Delta, | ||
}); | ||
|
||
for (let k = LB; k <= UB; k += 2) { | ||
const x = V[center + k]; | ||
const y = x - (k + Delta); | ||
console.debug({k, x, lj, y, rj}); | ||
|
||
if (x >= lj && y >= rj && x <= li && y <= ri) { | ||
V[center + k] = longestCommonSuffix(eq, x, lj, y, rj); | ||
} | ||
} | ||
|
||
console.debug('end backwardExtend', { | ||
center, | ||
D, | ||
V, | ||
eq, | ||
li, | ||
lj, | ||
ri, | ||
rj, | ||
Delta, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters