removed bootstrap test to allow reversed search

This commit is contained in:
wumpz
2017-04-13 08:45:02 +02:00
parent cb8e8bfa89
commit 1abc148dfe
2 changed files with 8 additions and 5 deletions

View File

@@ -111,7 +111,7 @@ public final class MyersDiff<T> implements DiffAlgorithm<T> {
final int middle = size / 2;
final PathNode diagonal[] = new PathNode[size];
diagonal[middle + 1] = new PathNode(0, -1, true, null);
diagonal[middle + 1] = new PathNode(0, -1, true, true, null);
for (int d = 0; d < MAX; d++) {
for (int k = -d; k <= d; k += 2) {
final int kmiddle = middle + k;
@@ -132,7 +132,7 @@ public final class MyersDiff<T> implements DiffAlgorithm<T> {
int j = i - k;
PathNode node = new PathNode(i, j, false, prev);
PathNode node = new PathNode(i, j, false, false, prev);
while (i < N && j < M && equalizer.equals(orig.get(i), rev.get(j))) {
i++;
@@ -140,7 +140,7 @@ public final class MyersDiff<T> implements DiffAlgorithm<T> {
}
if (i != node.i) {
node = new PathNode(i, j, true, node);
node = new PathNode(i, j, true, false, node);
}
diagonal[kmiddle] = node;

View File

@@ -44,6 +44,8 @@ public final class PathNode {
public final PathNode prev;
public final boolean snake;
public final boolean bootstrap;
/**
* Concatenates a new path node with an existing diffpath.
@@ -52,9 +54,10 @@ public final class PathNode {
* @param j The position in the revised sequence for the new node.
* @param prev The previous node in the path.
*/
public PathNode(int i, int j, boolean snake, PathNode prev) {
public PathNode(int i, int j, boolean snake, boolean bootstrap, PathNode prev) {
this.i = i;
this.j = j;
this.bootstrap = bootstrap;
if (snake) {
this.prev = prev;
} else {
@@ -75,7 +78,7 @@ public final class PathNode {
* @return tru if this is a bootstrap node.
*/
public boolean isBootstrap() {
return i < 0 || j < 0;
return bootstrap;
}
/**