private List <string> Match(BKTreeNode node, string word, int tolerance) { List <string> result = new List <string>(); int dist = GetLevenstheinDistance(node.Value, word); if (dist <= tolerance) { result.Add(node.Value); } int lowerDist = dist - tolerance > 0 ? dist - tolerance : 1; int upperDist = dist + tolerance; for (int i = upperDist; i >= lowerDist; i--) { if (node.GetChild(i) != null) { var nodeResult = Match(node.GetChild(i), word, tolerance); foreach (var match in nodeResult) { result.Add(match); } } } return(result); }
private void AddToChildren(BKTreeNode node, string value) { int levenstheinDist = GetLevenstheinDistance(node.Value, value); if (node.GetChild(levenstheinDist) == null) { node.Add(levenstheinDist, value); } else { AddToChildren(node.GetChild(levenstheinDist), value); } }