Object DiffEngine

  • All Implemented Interfaces:

    
    public class DiffEngine
    
                        

    Line-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 class DiffEngine.Edit

      A single line-level edit.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final static DiffEngine INSTANCE
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description