private void BuildRightToLeftLineMap() { int left = 0; int right = 0; while (right < RightTextLines.Count) { var difference = Differences.Where(d => right >= d.Right.Start && right < d.Right.Start + d.Right.Length).SingleOrDefault(); if (difference == null) { difference = Differences.Where(d => d.DifferenceType == DifferenceType.Remove && d.Right.Start == right).SingleOrDefault(); } if (difference == null) { RightToLeftLineMap[right++] = left++; } else { if (difference.DifferenceType == DifferenceType.Add) { for (right = difference.Right.Start; right < difference.Right.Start + difference.Right.Length; right++) { RightToLeftLineMap[right] = null; } } if (difference.DifferenceType == DifferenceType.Remove) { left = difference.Left.Start + difference.Left.Length; RightToLeftLineMap[right++] = left++; } if (difference.DifferenceType == DifferenceType.Change) { if (difference.Left.Length == difference.Right.Length) { // This is one-to-one mod. for (right = difference.Right.Start; right < difference.Right.Start + difference.Right.Length; right++, left++) { RightToLeftLineMap[right] = left; } } else { var dict = BackwardMatchChangeLinesAcrossDiff(difference); foreach (var entry in dict) { RightToLeftLineMap[entry.Key] = entry.Value; right++; } left = difference.Left.Start + difference.Left.Length; } } } } if (RightToLeftLineMap.Count != RightTextLines.Count) { throw new Exception("Messed up right to left line map"); } }
public void GetMatrix(out Verdict[] usedVerdicts, out int[,] matrix) { var optts = Differences .Where(s => s.NewJudging.Status != Verdict.Pending) .Where(s => s.NewJudging.Status != Verdict.Running); var verds = optts .Select(s => new { Old = s.OldJudging.Status, New = s.NewJudging.Status }) .ToList(); usedVerdicts = verds .SelectTwo(a => a.New, a => a.Old) .Distinct() .OrderBy(v => v) .ToArray(); matrix = new int[usedVerdicts.Length, usedVerdicts.Length]; var rev = new int[13]; for (int i = 0; i < usedVerdicts.Length; i++) { rev[(int)usedVerdicts[i]] = i; } foreach (var s in verds) { matrix[rev[(int)s.Old], rev[(int)s.New]]++; } }
public Difference GetLeftStatus(int index) { return(Differences.Where(d => index >= d.Left.Start && index < d.Left.Start + d.Left.Length).SingleOrDefault()); }
private void BuildLeftToRightLineMap() { int left = 0; int right = 0; while (left < LeftTextLines.Count) { var difference = Differences.Where(d => left >= d.Left.Start && left < d.Left.Start + d.Left.Length).SingleOrDefault(); if (difference == null) { difference = Differences.Where(d => d.DifferenceType == DifferenceType.Add && d.Left.Start == left).SingleOrDefault(); } if (difference == null) { LeftToRightLineMap[left++] = right++; } else { if (difference.DifferenceType == DifferenceType.Add) { right = difference.Right.Start + difference.Right.Length; LeftToRightLineMap[left++] = right++; } if (difference.DifferenceType == DifferenceType.Remove) { for (left = difference.Left.Start; left < difference.Left.Start + difference.Left.Length; left++) { LeftToRightLineMap[left] = null; } } if (difference.DifferenceType == DifferenceType.Change) { if (difference.Left.Length == difference.Right.Length) { // This is one-to-one mod. for (left = difference.Left.Start; left < difference.Left.Start + difference.Left.Length; left++, right++) { LeftToRightLineMap[left] = right; } } else { // This is really an add mixed in with changes such as line position, e.g.: // 120..121 // var foo = 2; //} => // 120..123 // var foo = 2; // mod from newline // // // some code // } var dict = ForwardMatchChangeLinesAcrossDiff(difference); foreach (var entry in dict) { LeftToRightLineMap[entry.Key] = entry.Value; left++; } right = difference.Right.Start + difference.Right.Length; } } } } if (LeftToRightLineMap.Count != LeftTextLines.Count) { throw new Exception("Messed up left to right line map"); } }