private static void ProcessCommon(ref CommonOrDifferentThing common, List <CommonOrDifferentThing> result) { if (common.Common.Count > 0) { common.Common.Reverse(); result.Add(common); common = new CommonOrDifferentThing(); } }
public static List <CommonOrDifferentThing> DiffComm(string[] file1, string[] file2) { // We apply the LCS to build a "comm"-style picture of the // differences between File1 and File2. var result = new List <CommonOrDifferentThing>(); int tail1 = file1.Length; int tail2 = file2.Length; CommonOrDifferentThing common = new CommonOrDifferentThing { Common = new List <string>() }; for (var candidate = Diff.LongestCommonSubsequence(file1, file2); candidate != null; candidate = candidate.Chain) { CommonOrDifferentThing different = new CommonOrDifferentThing { File1 = new List <string>(), File2 = new List <string>() }; while (--tail1 > candidate.File1Index) { different.File1.Add(file1[tail1]); } while (--tail2 > candidate.File2Index) { different.File2.Add(file2[tail2]); } if (different.File1.Count > 0 || different.File2.Count > 0) { ProcessCommon(ref common, result); different.File1.Reverse(); different.File2.Reverse(); result.Add(different); } if (tail1 >= 0) { common.Common.Add(file1[tail1]); } } ProcessCommon(ref common, result); result.Reverse(); return(result); }
/// <summary> /// We apply the LCS to build a "comm"-style picture of the /// differences between file1 and file2. /// </summary> /// <param name="file1"></param> /// <param name="file2"></param> /// <returns></returns> public static List <CommonOrDifferentThing> DiffComm(string[] file1, string[] file2) { var result = new List <CommonOrDifferentThing>(); var tail1 = file1.Length; var tail2 = file2.Length; var common = new CommonOrDifferentThing { Common = new List <string>() }; for (var candidate = LongestCommonSubsequence(file1, file2); candidate != null; candidate = candidate.Chain) { var different = new CommonOrDifferentThing { File1 = new List <string>(), File2 = new List <string>() }; while (--tail1 > candidate.File1Index) { different.File1.Add(file1[tail1]); } while (--tail2 > candidate.File2Index) { different.File2.Add(file2[tail2]); } if (different.File1.Count > 0 || different.File2.Count > 0) { ProcessCommon(ref common, result); different.File1.Reverse(); different.File2.Reverse(); result.Add(different); } if (tail1 >= 0) { common.Common.Add(file1[tail1]); } } ProcessCommon(ref common, result); result.Reverse(); return(result); }