public bool removeExistingLower(CharacterMatch currentMatch) { var ix = -1; for (var i = 0; i != count; i++) { if (matches[i].Character == currentMatch.Character) { ix = i; break; } } if (ix == -1) { return(false); } if (currentMatch.Score <= matches[ix].Score) { return(true); } for (var i = ix; i < matches.Count - 1; ++i) { matches[i] = matches[i + 1]; } count--; return(false); }
public void AddMatch(CharacterMatch currentMatch) { if (count == matches.Count && currentMatch.Score <= matches[matches.Count - 1].Score) { return; } if (removeExistingLower(currentMatch)) { return; } var pos = findSlot(currentMatch.Score); for (int i = matches.Count - 1; i > pos; i--) { matches[i] = matches[i - 1]; } if (count < matches.Count) { count++; } matches[pos] = currentMatch; }
public char[] DoMatching(JObject data) { int strokeCount = strokesCount; int subStrokeCount = subStrokesCount; List <SubStroke> inputSubStrokes = this.inputSubStrokes; int strokeRange = getStrokesRange(strokeCount); int minimumStrokes = Math.Max(strokeCount - strokeRange, 1); int maximumStrokes = Math.Min(strokeCount + strokeRange, CharConstants.MAX_CHARACTER_STROKE_COUNT); int subStrokesRange = getSubStrokesRange(subStrokeCount); var minSubStrokes = Math.Max(subStrokeCount - subStrokesRange, 1); var maxSubStrokes = Math.Min(subStrokeCount + subStrokesRange, CharConstants.MAX_CHARACTER_SUB_STROKE_COUNT); subStrInf = data["substrokes"]; var symbols = data["chars"] as JArray; for (int i = 0; i <= symbols.Count - 1; i++) { var repoChar = symbols[i]; int cmpStrokeCount = repoChar[1].ToObject <int>(); int cmpSubStrokes = repoChar[2].ToObject <int>(); if (cmpStrokeCount < minimumStrokes || cmpStrokeCount > maximumStrokes) { continue; } if (cmpSubStrokes < minSubStrokes || cmpSubStrokes > maxSubStrokes) { continue; } jarrayObj.Add(symbols[i]); CharacterMatch match = this.matchOne(strokeCount, inputSubStrokes, subStrokesRange, repoChar); matchCollector.AddMatch(match); } char[] resultChars = matchCollector.matches.Where(x => x != null).Select(x => x.Character).ToArray(); return(resultChars); }