www.mathertel.deAn O(ND) Difference Algorithm for C#

An O(ND) Difference Algorithm for C#

Here you can find an C# implementation of the famous algorithm that finds the best diff of 2 inputs. You can use it for text documents and compare the complete lines, for a text lines and compare the characters or just to compare 2 arrays of numbers. This algorithm is used by many applications that need to find the best way to describe the difference e.g. to extract it as a patch.

This implementation is based on the algorithm published in "An O(ND) Difference Algorithm and its Variations" by Eugene Myers Algorithmica Vol. 1 No. 2, 1986, p 251.

The source code that you can find in the download implements a small class with a simple to use API that just does this job. You should have it in the bag of your algorithms.

The core algorithm is comparing 2 arrays of numbers so when you like to find differences in text files you need a small converter that is also included in the implementation because this is the most used purpose.

Documentation and source code:

The documentation:
This is a detailed documentation for the Diff class that explains some of the backgrounds, concepts and the API.

Diff characters:
This is a step by step sample how to use the Diff class for comparing 2 strings on a character basis.

Source code:
The Source code (25 kByte for the class) is availabe as a zip archive. You can also view the source code directly through: ViewSrc

Sample diff results using the older and actual versions of the Diff source code:

These links use the difference algorithm for comparing files and formatting the result as HTML. You can follow the evolution of it since 2002. There was no need for a bug fixing since February 2003:

This page is part of the http://www.mathertel.de/ web site.