MyersDiff 0.5.0

dotnet add package MyersDiff --version 0.5.0
                    
NuGet\Install-Package MyersDiff -Version 0.5.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MyersDiff" Version="0.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MyersDiff" Version="0.5.0" />
                    
Directory.Packages.props
<PackageReference Include="MyersDiff" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MyersDiff --version 0.5.0
                    
#r "nuget: MyersDiff, 0.5.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MyersDiff@0.5.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MyersDiff&version=0.5.0
                    
Install as a Cake Addin
#tool nuget:?package=MyersDiff&version=0.5.0
                    
Install as a Cake Tool

Myers' difference algorithm Nuget Version

A C# implementation of Eugene Myers' O(ND) difference algorithm for computing the longest common subsequence (LCS), shortest edit script (SES), and full diff between two sequences.

Features

  • Generic — works with any element type via ReadOnlySpan<T>
  • Custom equality comparers via IEqualityComparer<T>
  • Linear-space divide-and-conquer implementation
  • Zero external dependencies

Longest Common Subsequence

List<char> subsequence = Algorithm.ComputeLcs<char>("abcabba", "cbabac");

// ['b', 'a', 'b', 'a']

With an explicit comparer:

List<char> subsequence = Algorithm.ComputeLcs("abcabba", "cbabac", EqualityComparer<char>.Default);

// ['b', 'a', 'b', 'a']

Shortest Edit Script

List<Edit<char>> script = Algorithm.ComputeSes<char>("abcabba", "cbabac");

// [Insert(0, c), Delete(1), Delete(3), Delete(6), Insert(7, c)]

foreach (var command in script)
{
    switch (command)
    {
        case Edit<char>.Delete delete:
            Console.WriteLine($"Delete at position {delete.Position}");
            break;
        case Edit<char>.Insert insert:
            Console.WriteLine($"Insert '{insert.Element}' at position {insert.Position}");
            break;
    }
}

With an explicit comparer:

List<Edit<char>> script = Algorithm.ComputeSes("abcabba", "cbabac", EqualityComparer<char>.Default);

// [Insert(0, c), Delete(1), Delete(3), Delete(6), Insert(7, c)]

Diff

string a = "abcabba";
string b = "cbabac";

List<Diff> diffs = Algorithm.ComputeDiff<char>(a, b);

Algorithm.ReorderDeletesBeforeInserts(diffs);

foreach (var diff in diffs)
{
    switch (diff)
    {
        case Diff.Delete del:
            Console.WriteLine($"- {a[del.X - 1]}");
            break;
        case Diff.Insert ins:
            Console.WriteLine($"+ {b[ins.Y - 1]}");
            break;
        case Diff.Equal eq:
            Console.WriteLine($"  {a[eq.X - 1]}");
            break;
    }
}

// - a
// + c
//   b
// - c
//   a
//   b
// - b
//   a
// + c

With an explicit comparer:

List<Diff> diffs = Algorithm.ComputeDiff("abcabba", "cbabac", EqualityComparer<char>.Default);

Reordering deletions before insertions

By default, within each non-equal block the algorithm emits insertions before deletions. Call Algorithm.ReorderDeletesBeforeInserts to flip the order so that all deletions appear first — useful when rendering traditional unified diffs where - lines precede + lines.

List<Diff> diffs = Algorithm.ComputeDiff<char>(a, b);

Algorithm.ReorderDeletesBeforeInserts(diffs);

References

  • Myers, E.W. An O(ND) difference algorithm and its variations. Algorithmica 1, 251–266 (1986). PDF
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0 55 4/2/2026
0.3.0 72 4/1/2026
0.2.2 88 3/31/2026
0.2.1 78 3/31/2026
0.2.0 79 3/30/2026
0.1.0 78 3/30/2026