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 string FormatCode(string code) { var withoutWhiteSpace = new List <char>(code.Length); foreach (var ch in code) { if (!char.IsWhiteSpace(ch)) { withoutWhiteSpace.Add(ch); } } var withoutWhiteSpaceArray = withoutWhiteSpace.ToArray(); var ignored = new bool[withoutWhiteSpace.Count]; var deep = 0; for (var i = 0; i < withoutWhiteSpace.Count; i++) { deep = Math.Max(deep, Bor.GetDeep(withoutWhiteSpaceArray, i)); if (deep > 0) { ignored[i] = true; deep--; } } var res = new StringBuilder(); var p = 0; foreach (var ch in code) { if (char.IsWhiteSpace(ch)) { res.Append(ch); } else { if (!ignored[p]) { res.Append(ch); } p++; } } return(res.ToString()); }