public override decimal Compare(CodeAnalyzer code) { if (code is SuffixTreeCodeAnalyzer) { var suffixCode = code as SuffixTreeCodeAnalyzer; if (suffixCode.CodeLines.Length > CodeLines.Length) { return(code.Compare(this)); } // TODO : Remove? var deeps = new List <long>(); var lengs = new List <long>(); long length = 0; var minDeep = 1; for (var i = 0; i < suffixCode.CodeLines.Length;) { int deep = SuffixTree.GetDeep(suffixCode.CodeLines, i); if (deep < minDeep) { i++; continue; } else { var leng = Magic(deep); for (var j = 0; j < deep; j++) { leng += suffixCode.CodeLines[j + i].Length; } deeps.Add(deep); lengs.Add(leng); length += leng; i += deep; } } decimal a = length; decimal b = ParsedCodeLength + Magic(CodeLines.Length); if (b == 0) { return(a == 0 ? 1 : 0); } return(a / b); } else { return(base.Compare(code)); } }
public override decimal Compare(CodeAnalyzer code) { if (code is LevenshteinCodeAnalyzer) { var levenshtein = code as LevenshteinCodeAnalyzer; //if (code.Language != Language) return 0; var f1 = hashes; var f2 = levenshtein.hashes; for (int i = 1; i < Math.Max(f1.Count, f2.Count); i++) { arr[0, i] = arr[i, 0] = i; } for (int i = 1; i <= f1.Count; i++) { for (int j = 1; j <= f2.Count; j++) { arr[i, j] = Math.Min(Math.Min(arr[i, j - 1], arr[i - 1, j]) + 1, (arr[i - 1, j - 1] + (f1[i - 1] != f2[j - 1] ? 1 : 0))); } } long ans = arr[f1.Count, f2.Count]; if (ans * alpha1 < Math.Min(f1.Count, f2.Count)) { return(1); } int c = 0; for (int i = 0; i < f1.Count; i++) { if (f2.Contains(f1[i])) { c++; } } if (c * alpha2 > f1.Count) { return(0.99M); } c = 0; for (int i = 0; i < f2.Count; i++) { if (f1.Contains(f2[i])) { c++; } } if (c * alpha2 > f2.Count) { return(0.99M); } return(0); } else { return(base.Compare(code)); } }
public virtual decimal Compare(CodeAnalyzer code) { if (code.Code == Code) { return(1); } else { return(0); } }