public void Add(string word, int wordScore) { if (word.Length > 0) { char first = word[0]; string next = word.Substring(1); WordRoot root = null; if (this.nodes == null) { this.nodes = new Dictionary <char, WordRoot>(); } if (!this.nodes.TryGetValue(first, out root)) { root = new WordRoot(); this.nodes.Add(first, root); } root.Add(next, wordScore); } else { this.score = wordScore; } }
public void Search(string input, int index, List <Tuple <string, int> > candidates) { if (this.score != -1) { candidates.Add(Tuple.Create(input.Substring(0, index), this.score)); } if (index < input.Length && this.nodes != null) { char first = input[index]; WordRoot root = null; if (this.nodes.TryGetValue(first, out root)) { root.Search(input, index + 1, candidates); } } }