GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — first implementation of meyers diff with linear space · marisaroman/java-diff-utils@9765052

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • java-diff-utils/src
    • main/java/com/github/difflib/algorithm
      • Change.java
      • myers
        • MeyersDiffWithLinearSpace.java
    • test/java/com/github/difflib/algorithm/myers
      • WithMeyersDiffWithLinearSpacePatchTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎java-diff-utils/src/main/java/com/github/difflib/algorithm/Change.java‎

Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/algorithm/Change.java
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,12 @@ public Change(DeltaType deltaType, int startOriginal, int endOriginal, int start
3636
this.startRevised = startRevised;
3737
this.endRevised = endRevised;
3838
}
39+
40+
public Change withEndOriginal(int endOriginal) {
41+
return new Change(deltaType, startOriginal, endOriginal, startRevised, endRevised);
42+
}
43+
44+
public Change withEndRevised(int endRevised) {
45+
return new Change(deltaType, startOriginal, endOriginal, startRevised, endRevised);
46+
}
3947
}
Collapse file

‎java-diff-utils/src/main/java/com/github/difflib/algorithm/myers/MeyersDiffWithLinearSpace.java‎

Copy file name to clipboardExpand all lines: java-diff-utils/src/main/java/com/github/difflib/algorithm/myers/MeyersDiffWithLinearSpace.java
+14-3Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,22 @@ private void buildScript(DiffData data, int start1, int end1, int start2, int en
6565
//TODO: compress these commands.
6666
if (end1 - start1 > end2 - start2) {
6767
//script.append(new DeleteCommand<>(left.charAt(i)));
68-
data.script.add(new Change(DeltaType.DELETE, i, i + 1, j, j));
68+
if (data.script.isEmpty()
69+
|| data.script.get(data.script.size() - 1).endOriginal != i
70+
|| data.script.get(data.script.size() - 1).deltaType != DeltaType.DELETE) {
71+
data.script.add(new Change(DeltaType.DELETE, i, i + 1, j, j));
72+
} else {
73+
data.script.set(data.script.size() - 1, data.script.get(data.script.size() - 1).withEndOriginal(i + 1));
74+
}
6975
++i;
7076
} else {
71-
//script.append(new InsertCommand<>(right.charAt(j)));
72-
data.script.add(new Change(DeltaType.INSERT, i, i, j, j + 1));
77+
if (data.script.isEmpty()
78+
|| data.script.get(data.script.size() - 1).endRevised != j
79+
|| data.script.get(data.script.size() - 1).deltaType != DeltaType.INSERT) {
80+
data.script.add(new Change(DeltaType.INSERT, i, i, j, j + 1));
81+
} else {
82+
data.script.set(data.script.size() - 1, data.script.get(data.script.size() - 1).withEndRevised(j + 1));
83+
}
7384
++j;
7485
}
7586
}
Collapse file

‎java-diff-utils/src/test/java/com/github/difflib/algorithm/myers/WithMeyersDiffWithLinearSpacePatchTest.java‎

Copy file name to clipboardExpand all lines: java-diff-utils/src/test/java/com/github/difflib/algorithm/myers/WithMeyersDiffWithLinearSpacePatchTest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testPatch_Change_withExceptionProcessor() {
9393

9494
try {
9595
List<String> data = DiffUtils.patch(changeTest_from, patch);
96-
assertEquals(9, data.size());
96+
assertEquals(11, data.size());
9797

9898
assertEquals(Arrays.asList("aaa", "<<<<<< HEAD", "bbb", "CDC", "======", "bbb", "ccc", ">>>>>>> PATCH", "ddd"), data);
9999

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.