/// <summary> /// Builds the resulted words from a one word. Searches for all descendants which match that word. /// The word is being built by the node itself. As it iterates its parents until the end of a word or the root are met. /// </summary> /// <param name="nodeValue">The node to build results from</param> /// <param name="results">Output</param> private void BuildResultsFromSubstring(TrieNode nodeValue, ICollection <string> results) { string builtWord = nodeValue.BuildUpToWord(); if (nodeValue.Children.Count == 0) { //if we at the bottom of the tree just add this word as no descendants will be found results.Add(builtWord); } else { //Using a DepthFirstApproach (http://en.wikipedia.org/wiki/Depth-first_search) finds all descendants of the current node and adds their //values to the results. this.DfsForAllWords(nodeValue, new StringBuilder(builtWord), results); } }
/// <summary> /// Builds the resulted words from a one word. Searches for all descendants which match that word. /// The word is being built by the node itself. As it iterates its parents until the end of a word or the root are met. /// </summary> /// <param name="nodeValue">The node to build results from</param> /// <param name="results">Output</param> protected virtual void BuildResultsFromSubstring(TrieNode nodeValue, ICollection <string> results, int nrOfHits) { if (results.Count > nrOfHits) { return; } string builtWord = nodeValue.BuildUpToWord(); if (nodeValue.Children.Count == 0) { //if we at the bottom of the tree just add this word as no descendants will be found results.Add(builtWord); } else { if (results.Count > nrOfHits) { return; } DepthFirstSearchAllWords(nodeValue, new StringBuilder(builtWord), results, nrOfHits); } }