A year or so ago I wrote a diff application similar to windiff based upon the core algorithm discussed in A Fast Diff Algorithm in Visual Basic .Net. Somewhere along the way of upgrading my computer I lost that application. I decided to go back and recreate that application, but this time focus on using LINQ as much as possible in the implementation. It is probably not the fastest, but it is intended to be an exercise in incorporating LINQ in the implementation of an algorithm.
What I have at this point is code that will find the longest common sequence (LCS) of two string arrays. An extension method, LCS, is available on any string collections that implements the IEnumerable
Example:
string[] org = {"A","A","z", "A"};
string[] cmp = {"z", "A", "A", "A", "A"};
DiffInfo d = org.LCS(cmp);
//index = 0
Console.WriteLine("LCS start in orginal " + d.OriginalStartPos.ToString());
//index = 1
Console.WriteLine("LCS start in compared " + d.ComparedStartPos.ToString());
// length = 2
Console.WriteLine("Length of LCS " + d.Length);
Code available here
Monday, April 7, 2008
Diff Algorithm with LINQ
Posted by
K Jacobson
at
7:48 AM
Subscribe to:
Post Comments (Atom)
1 comments:
thanks for sharing this site. you can download lots of ebooks from here
http://feboook.blogspot.com
Post a Comment