public void Add(string word) { word = word.ToLower(); if (_Root == null) { _Root = new Node(word); return; } var curNode = _Root; var dist = DahmerauLevenshteinAlg.Compute(curNode.Word, word); while (curNode.ContainsKey(dist)) { if (dist == 0) { return; } curNode = curNode[dist]; dist = DahmerauLevenshteinAlg.Compute(curNode.Word, word); } curNode.AddChild(dist, word); }
private void RecursiveSearch(Node node, List <string> rtn, string word, int d) { var curDist = DahmerauLevenshteinAlg.Compute(node.Word, word); var minDist = curDist - d; var maxDist = curDist + d; if (curDist <= d) { rtn.Add(node.Word); } foreach (var key in node.Keys.Cast <int>().Where(key => minDist <= key && key <= maxDist)) { RecursiveSearch(node[key], rtn, word, d); } }