MyersDiff 0.2.2

dotnet add package MyersDiff --version 0.2.2
                    
NuGet\Install-Package MyersDiff -Version 0.2.2
                    
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.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MyersDiff" Version="0.2.2" />
                    
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.2.2
                    
#r "nuget: MyersDiff, 0.2.2"
                    
#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.2.2
                    
#: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.2.2
                    
Install as a Cake Addin
#tool nuget:?package=MyersDiff&version=0.2.2
                    
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) and Shortest Edit Script (SES) between two sequences.

Features

  • Generic — works with any element type via ReadOnlySpan<T>
  • Custom equality comparers via IEqualityComparer<T>
  • Zero external dependencies

Longest Common Subsequence

List<char> lcs = Lcs<char>.Build("abcabba", "cbabac");

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

With an explicit comparer:

List<char> lcs = Lcs<char>.Build("abcabba", "cbabac", EqualityComparer<char>.Default);

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

Shortest Edit Script

List<Ses<char>.Cmd> ses = Ses<char>.Build("abcabba", "cbabac");

// [Del(1), Del(2), Ins(3, 'b'), Del(6), Ins(7, 'c')]

foreach (var cmd in ses)
{
    switch (cmd)
    {
        case Ses<char>.Cmd.Del del:
            Console.WriteLine($"Delete at position {del.Pos}");
            break;
        case Ses<char>.Cmd.Ins ins:
            Console.WriteLine($"Insert '{ins.El}' at position {ins.Pos}");
            break;
    }
}

With an explicit comparer:

List<Ses<char>.Cmd> ses = Ses<char>.Build("abcabba", "cbabac", EqualityComparer<char>.Default);

// [Del(1), Del(2), Ins(3, 'b'), Del(6), Ins(7, 'c')]

Custom Trace Logic

The Path, Vector, and Trace types are public, so you can call Algorithm.LcsSes directly and implement your own trace logic on top of the recorded snapshots.

For example, building a unified diff-style output:

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

var path = Algorithm.LcsSes(a, b, EqualityComparer<char>.Default);

var filter = Trace.Filter.Del | Trace.Filter.Ins | Trace.Filter.Eq;

foreach (var edit in Trace.GetEdits(path, filter))
{
    switch (edit.Op)
    {
        case Trace.Op.Del:
            Console.WriteLine($"- {a[edit.X - 1]}");
            break;
        case Trace.Op.Ins:
            Console.WriteLine($"+ {b[edit.Y - 1]}");
            break;
        case Trace.Op.Eq:
            Console.WriteLine($"  {a[edit.X - 1]}");
            break;
    }
}

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

Limitations

The linear-space refinement (divide-and-conquer) described in the original paper is not yet implemented. The current implementation stores the full snapshot history during the forward pass. This is planned for a future release.

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.2.2 0 3/31/2026
0.2.1 0 3/31/2026
0.2.0 38 3/30/2026
0.1.0 37 3/30/2026