Skip to content

Commit 123cbc2

Browse files
committed
Merge branch 'dev'
# Conflicts: # version.txt
2 parents 5502348 + 0bd2ff8 commit 123cbc2

27 files changed

Lines changed: 791 additions & 283 deletions

src/main/java/org/pageseeder/diffx/algorithm/HirschbergAlgorithm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
* @author Christophe Lauret
4040
*
41-
* @version 1.3.1
41+
* @version 1.3.2
4242
* @since 0.9.0
4343
*/
4444
public final class HirschbergAlgorithm<T> implements DiffAlgorithm<T> {
@@ -156,7 +156,7 @@ private void algorithmC(int m, int n, List<? extends T> a, List<? extends T> b,
156156
T a0 = a.get(0);
157157
for (int j = 0; j < n; j++) {
158158
if (this.eq.equals(a0, b.get(j)) && !match) {
159-
handler.handle(Operator.MATCH, a0);
159+
handler.handle(Operator.MATCH, b.get(j));
160160
match = true;
161161
} else {
162162
handler.handle(Operator.INS, b.get(j));

src/main/java/org/pageseeder/diffx/algorithm/KumarRanganAlgorithm.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
* @author Christophe Lauret
3939
*
40-
* @version 1.3.1
40+
* @version 1.3.2
4141
* @since 0.9.0
4242
*/
4343
public final class KumarRanganAlgorithm<T> implements DiffAlgorithm<T> {
@@ -388,7 +388,7 @@ private void computeLCSBaseCase(int startA, int endA, int startB, int endB, int
388388

389389
// 2. Start in order for the A subsequence and get the index of the B subsequence
390390
while (i < p && this.eq.equals(this.A.get(i + startA), this.B.get(this.LL[p - i] - 1 + startB))) {
391-
this.handler.handle(Operator.MATCH, this.A.get(i + startA));
391+
this.handler.handle(Operator.MATCH, this.B.get(this.LL[p - i] - 1 + startB));
392392
this.J++;
393393
i++;
394394
if (i < p) {
@@ -407,7 +407,7 @@ private void computeLCSBaseCase(int startA, int endA, int startB, int endB, int
407407

408408
// 4. The second part of the A subsequence
409409
while (i < m) {
410-
this.handler.handle(Operator.MATCH, this.A.get(i + startA));
410+
this.handler.handle(Operator.MATCH, this.B.get(this.J));
411411
this.J++;
412412
i++;
413413

src/main/java/org/pageseeder/diffx/algorithm/MatrixXMLAlgorithm.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*
3333
* @author Christophe Lauret
3434
*
35-
* @version 1.3.1
35+
* @version 1.3.2
3636
* @since 0.9.0
3737
*/
3838
public final class MatrixXMLAlgorithm implements DiffAlgorithm<XMLToken> {
@@ -192,11 +192,11 @@ private void processDiff(List<? extends XMLToken> A, List<? extends XMLToken> B,
192192
i++;
193193

194194
// if we can format checking at the stack, let's do it
195-
} else if (this.eq.equals(tokenA, tokenB) && handler.isAllowed(Operator.MATCH, tokenA)) {
195+
} else if (this.eq.equals(tokenA, tokenB) && handler.isAllowed(Operator.MATCH, tokenB)) {
196196
if (DEBUG) {
197-
System.err.print("[" + i + "," + j + "]->[" + (i + 1) + "," + (j + 1) + "] >f " + tokenA);
197+
System.err.print("[" + i + "," + j + "]->[" + (i + 1) + "," + (j + 1) + "] >f " + tokenB);
198198
}
199-
handler.handle(Operator.MATCH, tokenA);
199+
handler.handle(Operator.MATCH, tokenB);
200200
i++;
201201
j++;
202202

@@ -227,11 +227,11 @@ private void processDiff(List<? extends XMLToken> A, List<? extends XMLToken> B,
227227
j++;
228228

229229
// if we can format checking at the stack, let's do it
230-
} else if (this.eq.equals(tokenA, tokenB) && handler.isAllowed(Operator.MATCH, tokenA)) {
230+
} else if (this.eq.equals(tokenA, tokenB) && handler.isAllowed(Operator.MATCH, tokenB)) {
231231
if (DEBUG) {
232-
System.err.print("[" + i + "," + j + "]->[" + (i + 1) + "," + (j + 1) + "] <f " + tokenA);
232+
System.err.print("[" + i + "," + j + "]->[" + (i + 1) + "," + (j + 1) + "] <f " + tokenB);
233233
}
234-
handler.handle(Operator.MATCH, tokenA);
234+
handler.handle(Operator.MATCH, tokenB);
235235
i++;
236236
j++;
237237

@@ -255,11 +255,11 @@ private void processDiff(List<? extends XMLToken> A, List<? extends XMLToken> B,
255255
// we have to make a choice for where we are going
256256
} else if (matrix.isSameXY(i, j)) {
257257
// if we can format checking at the stack, let's do it
258-
if (this.eq.equals(tokenA, tokenB) && handler.isAllowed(Operator.MATCH, tokenA)) {
258+
if (this.eq.equals(tokenA, tokenB) && handler.isAllowed(Operator.MATCH, tokenB)) {
259259
if (DEBUG) {
260-
System.err.print("[" + i + "," + j + "]->[" + (i + 1) + "," + (j + 1) + "] =f " + tokenA);
260+
System.err.print("[" + i + "," + j + "]->[" + (i + 1) + "," + (j + 1) + "] =f " + tokenB);
261261
}
262-
handler.handle(Operator.MATCH, tokenA);
262+
handler.handle(Operator.MATCH, tokenB);
263263
i++;
264264
j++;
265265

src/main/java/org/pageseeder/diffx/algorithm/MyersAlgorithm.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import org.pageseeder.diffx.api.DiffAlgorithm;
1919
import org.pageseeder.diffx.api.DiffHandler;
20-
import org.pageseeder.diffx.api.Equality;
2120
import org.pageseeder.diffx.api.Operator;
2221

2322
import java.util.List;
@@ -35,7 +34,7 @@
3534
*
3635
* @author Christophe Lauret
3736
*
38-
* @version 1.3.1
37+
* @version 1.3.2
3938
* @since 0.9.0
4039
*/
4140
abstract class MyersAlgorithm<T> implements DiffAlgorithm<T> {
@@ -69,8 +68,8 @@ private void handleForward(List<? extends T> a, List<? extends T> b, DiffHandler
6968
Point end = snake.getEndPoint();
7069
handleEdited(a, b, handler, snake, start, mid);
7170
if (snake.matching > 0) {
72-
for (int i = mid.x(); i < end.x(); i++) {
73-
handler.handle(Operator.MATCH, a.get(i));
71+
for (int j = mid.y(); j < end.y(); j++) {
72+
handler.handle(Operator.MATCH, b.get(j));
7473
}
7574
}
7675
}
@@ -83,8 +82,8 @@ private void handleReverse(List<? extends T> a, List<? extends T> b, DiffHandler
8382
Point mid = snake.getMidPoint();
8483
Point end = snake.getStartPoint();
8584
if (snake.matching > 0) {
86-
for (int i = start.x(); i < mid.x(); i++) {
87-
handler.handle(Operator.MATCH, a.get(i));
85+
for (int j = start.y(); j < mid.y(); j++) {
86+
handler.handle(Operator.MATCH, b.get(j));
8887
}
8988
}
9089
handleEdited(a, b, handler, snake, mid, end);

src/main/java/org/pageseeder/diffx/algorithm/MyersGreedyAlgorithm.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
* @param <T> The type of token being compared
3232
*
3333
* @author Christophe Lauret
34+
*
35+
* @version 1.3.2
3436
* @version 0.9.0
37+
*
3538
* @see <a href="https://neil.fraser.name/writing/diff/myers.pdf">An O(ND) Difference Algorithm and its Variations</a>
3639
* @see <a href="http://simplygenius.net/Article/DiffTutorial1">Myers' Diff Algorithm: The basic greedy algorithm</a>
3740
*/
@@ -82,7 +85,7 @@ private void handle(List<? extends T> a, List<? extends T> b, DiffHandler<T> han
8285
y++;
8386
}
8487
for (int i = 0; i < snake.length(); i++) {
85-
handler.handle(Operator.MATCH, a.get(x));
88+
handler.handle(Operator.MATCH, b.get(y));
8689
x++;
8790
y++;
8891
}

src/main/java/org/pageseeder/diffx/algorithm/MyersGreedyAlgorithm2.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@
3434
*
3535
* @author Christophe Lauret
3636
*
37-
* @version 1.3.1
37+
* @version 1.3.2
3838
* @version 0.9.0
3939
*
4040
* @see <a href="https://neil.fraser.name/writing/diff/myers.pdf">An O(ND) Difference Algorithm and its Variations</a>
4141
* @see <a href="http://simplygenius.net/Article/DiffTutorial1">Myers' Diff Algorithm: The basic greedy algorithm</a>
4242
*/
4343
public final class MyersGreedyAlgorithm2<T> implements DiffAlgorithm<T> {
4444

45-
4645
/**
4746
* Determines the strategy to compare elements for equality within the diff algorithm.
4847
*/
@@ -180,7 +179,7 @@ private void solve(List<Vector> vectors, DiffHandler<T> handler) {
180179
int matching = Math.min(endX - startX, endY - startY);
181180
// Reverse: matching first
182181
for (int i = 0; i < matching; i++) {
183-
handler.handle(Operator.MATCH, a.get(x));
182+
handler.handle(Operator.MATCH, b.get(y));
184183
x++;
185184
y++;
186185
}

src/main/java/org/pageseeder/diffx/algorithm/MyersGreedyXMLAlgorithm.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
* @author Christophe Lauret
3333
*
34-
* @version 1.3.1
34+
* @version 1.3.2
3535
* @since 0.9.0
3636
*
3737
* @see <a href="https://neil.fraser.name/writing/diff/myers.pdf">An O(ND) Difference Algorithm and its Variations</a>
@@ -156,9 +156,9 @@ private boolean forward(Vector vector, XMLStackMap elements, int d) {
156156

157157
// Follow diagonals
158158
while (x < sizeA && y < sizeB && this.eq.equals(a.get(x), b.get(y))
159-
&& elements.isAllowed(k, Operator.MATCH, a.get(x))) {
160-
if (DEBUG) System.err.print(" =" + a.get(x));
161-
elements.update(k, Operator.MATCH, a.get(x));
159+
&& elements.isAllowed(k, Operator.MATCH, b.get(y))) {
160+
if (DEBUG) System.err.print(" =" + b.get(y));
161+
elements.update(k, Operator.MATCH, b.get(y));
162162
x++;
163163
y++;
164164
}

src/main/java/org/pageseeder/diffx/algorithm/WagnerFischerAlgorithm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @author Christophe Lauret
2929
*
30-
* @version 1.3.1
30+
* @version 1.3.2
3131
* @since 0.9.0
3232
*/
3333
public final class WagnerFischerAlgorithm<T> implements DiffAlgorithm<T> {
@@ -79,7 +79,7 @@ public void diff(List<? extends T> from, List<? extends T> to, DiffHandler<T> ha
7979
j++;
8080
} else if (matrix.isSameXY(i, j)) {
8181
if (this.eq.equals(t1, t2)) {
82-
handler.handle(Operator.MATCH, t1);
82+
handler.handle(Operator.MATCH, t2);
8383
i++;
8484
j++;
8585
} else {

0 commit comments

Comments
 (0)