Object DiffEngine
-
- All Implemented Interfaces:
public class DiffEngineLine-based diff engine with standard algorithms — Myers (default) and Patience.
Zero dependencies, pure Kotlin. Replaces the naive index-aligned line diff that produced noisy output whenever a single line was inserted mid-file.
Models diff as a shortest-path search on an (N+1)x(M+1) edit graph: right = delete old line, down = insert new line, diagonal = matching line (free). A greedy frontier over diagonals (k = x - y) finds the minimum edit path, preferring matches — so unchanged lines stay aligned. O((N+M)*D) time, O(N+M) space via trace-and-backtrack.
Git's alternative algorithm: anchors on lines that are unique in both inputs, matches anchors in order (longest-increasing-subsequence over their positions in the new file), then runs Myers on the gaps between anchors. Produces diffs that read more naturally for code (function moves, repeated boilerplate lines).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classDiffEngine.EditA single line-level edit.
-
Field Summary
Fields Modifier and Type Field Description public final static DiffEngineINSTANCE
-
Method Summary
Modifier and Type Method Description final List<DiffEngine.Edit>diff(List<String> old, List<String> new, String algorithm)Compute the line diff between old and new. final StringtoUnified(String oldPath, String newPath, List<DiffEngine.Edit> edits, Integer context)Render edits as a unified diff ( --- a//+++ b/header with hunks).
-