private Match ProcessMatch(Token working_a, Token working_b, Match currentMatch, CompareResult result) { if (currentMatch == null) { currentMatch = new Match(result); } currentMatch.TokensA.AddLast(working_a); currentMatch.TokensB.AddLast(working_b); return currentMatch; }
public Match(CompareResult parent) { this.Result = parent; this.TokensA = new LinkedList<Token>(); this.TokensB = new LinkedList<Token>(); }
public CompareResult Compare(Submission a, Submission b) { CompareResult result = new CompareResult(a, b); var matches = new List<Match>(); // reduce access to properties var a_length = a.Tokens.Length; var b_length = b.Tokens.Length; var a_tokens = a.Tokens; var b_tokens = b.Tokens; for (int idx_a = 0; idx_a < a_length; idx_a++) { int idx_working_a = idx_a; int inMatch = 0; Match currentMatch = null; for (int idx_working_b = 0; idx_working_b < b_length; idx_working_b++) { var working_a = a_tokens[idx_working_a]; var working_b = b_tokens[idx_working_b]; // reduce access to properties var a_text = working_a.Text; var b_text = working_b.Text; if (a_text == b_text) { currentMatch = ProcessMatch(working_a, working_b, currentMatch, result); idx_working_a++; if (idx_working_a >= a_length) break; inMatch = 1; } else if (inMatch > 0 && a_text != b_text) { if (inMatch >= _cfg.MAX_MATCH_DISTANCE) { FinishMatch(currentMatch, matches); currentMatch = null; inMatch = 0; } else { currentMatch = ProcessMatch(working_a, working_b, currentMatch, result); idx_working_a++; if (idx_working_a >= a_length) break; inMatch++; } } } // foreach(b) FinishMatch(currentMatch, matches); } // foreach(a) // Find longest match foreach (var match in matches.OrderByDescending(i => i.TokensA.Count)) { if (!result.Matches.Any(m => m.TokensA.Any(t => match.TokensA.Contains(t)) || m.TokensB.Any(t => match.TokensB.Contains(t)))) { match.Index = result.Matches.Count; result.Matches.Add(match); } } result.Update(); return result; }