Skip to content

Commit 1abc148

Browse files
committed
removed bootstrap test to allow reversed search
1 parent cb8e8bf commit 1abc148

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/main/java/difflib/algorithm/myers/MyersDiff.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private PathNode buildPath(final List<T> orig, final List<T> rev)
111111
final int middle = size / 2;
112112
final PathNode diagonal[] = new PathNode[size];
113113

114-
diagonal[middle + 1] = new PathNode(0, -1, true, null);
114+
diagonal[middle + 1] = new PathNode(0, -1, true, true, null);
115115
for (int d = 0; d < MAX; d++) {
116116
for (int k = -d; k <= d; k += 2) {
117117
final int kmiddle = middle + k;
@@ -132,15 +132,15 @@ private PathNode buildPath(final List<T> orig, final List<T> rev)
132132

133133
int j = i - k;
134134

135-
PathNode node = new PathNode(i, j, false, prev);
135+
PathNode node = new PathNode(i, j, false, false, prev);
136136

137137
while (i < N && j < M && equalizer.equals(orig.get(i), rev.get(j))) {
138138
i++;
139139
j++;
140140
}
141141

142142
if (i != node.i) {
143-
node = new PathNode(i, j, true, node);
143+
node = new PathNode(i, j, true, false, node);
144144
}
145145

146146
diagonal[kmiddle] = node;

src/main/java/difflib/algorithm/myers/PathNode.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public final class PathNode {
4444
public final PathNode prev;
4545

4646
public final boolean snake;
47+
48+
public final boolean bootstrap;
4749

4850
/**
4951
* Concatenates a new path node with an existing diffpath.
@@ -52,9 +54,10 @@ public final class PathNode {
5254
* @param j The position in the revised sequence for the new node.
5355
* @param prev The previous node in the path.
5456
*/
55-
public PathNode(int i, int j, boolean snake, PathNode prev) {
57+
public PathNode(int i, int j, boolean snake, boolean bootstrap, PathNode prev) {
5658
this.i = i;
5759
this.j = j;
60+
this.bootstrap = bootstrap;
5861
if (snake) {
5962
this.prev = prev;
6063
} else {
@@ -75,7 +78,7 @@ public boolean isSnake() {
7578
* @return tru if this is a bootstrap node.
7679
*/
7780
public boolean isBootstrap() {
78-
return i < 0 || j < 0;
81+
return bootstrap;
7982
}
8083

8184
/**

0 commit comments

Comments
 (0)