MCPcopy
hub / github.com/amark/gun / execEditLength

Function execEditLength

test/mocha.js:11569–11612  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11567
11568 // Main worker method. checks all permutations of a given edit length for acceptance.
11569 function execEditLength() {
11570 for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
11571 var basePath;
11572 var addPath = bestPath[diagonalPath - 1],
11573 removePath = bestPath[diagonalPath + 1],
11574 oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
11575 if (addPath) {
11576 // No one else is going to attempt to use this value, clear it
11577 bestPath[diagonalPath - 1] = undefined;
11578 }
11579
11580 var canAdd = addPath && addPath.newPos + 1 < newLen,
11581 canRemove = removePath && 0 <= oldPos && oldPos < oldLen;
11582 if (!canAdd && !canRemove) {
11583 // If this path is a terminal then prune
11584 bestPath[diagonalPath] = undefined;
11585 continue;
11586 }
11587
11588 // Select the diagonal that we want to branch from. We select the prior
11589 // path whose position in the new string is the farthest from the origin
11590 // and does not pass the bounds of the diff graph
11591 if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) {
11592 basePath = clonePath(removePath);
11593 self.pushComponent(basePath.components, undefined, true);
11594 } else {
11595 basePath = addPath; // No need to clone, we've pulled it from the list
11596 basePath.newPos++;
11597 self.pushComponent(basePath.components, true, undefined);
11598 }
11599
11600 oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
11601
11602 // If we have hit the end of both strings, then we are done
11603 if (basePath.newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
11604 return done(buildValues(basePath.components, newString, oldString, self.useLongestToken));
11605 } else {
11606 // Otherwise track this path as a potential candidate and continue.
11607 bestPath[diagonalPath] = basePath;
11608 }
11609 }
11610
11611 editLength++;
11612 }
11613
11614 // Performs the length of edit iteration. Is a bit fugly as this has to support the
11615 // sync and async mode which is never fun. Loops over execEditLength until a value

Callers 1

mocha.jsFile · 0.85

Calls 3

clonePathFunction · 0.85
buildValuesFunction · 0.85
doneFunction · 0.70

Tested by

no test coverage detected