GetChild() private method

private GetChild ( char character ) : TrieNode
character char
return TrieNode
Example #1
0
 /// <summary>
 /// Adds words recursively.
 /// <para>
 /// Gets the first char of the word, creates the child TrieNode if null,
 /// and recurses with the first char removed from the word. If the word
 /// length is 0, return.
 /// </para>
 /// </summary>
 private void AddWord(TrieNode trieNode, char[] word)
 {
     foreach (var c in word)
     {
         var child = trieNode.GetChild(c);
         if (child == null)
         {
             child = new TrieNode(c);
             trieNode.SetChild(child);
         }
         trieNode = child;
     }
     trieNode.WordCount++;
 }
Example #2
0
        /// <summary>
        /// Recursive method to add word. Gets the first char of the word,
        /// creates the child TrieNode if null, and recurses with the first
        /// char removed from the word. If the word length is 0, return.
        /// </summary>
        private void AddWord(TrieNode trieNode, char[] word)
        {
            if (word.Length == 0)
            {
                trieNode.WordCount++;
                return;
            }
            var      c     = Utilities.FirstChar(word);
            TrieNode child = trieNode.GetChild(c);

            if (child == null)
            {
                child = TrieFactory.CreateTrieNode(c, trieNode);
                trieNode.SetChild(child);
            }
            var cRemoved = Utilities.FirstCharRemoved(word);

            AddWord(child, cRemoved);
        }
Example #3
0
 /// <summary>
 /// Recursive method to add word. Gets the first char of the word, 
 /// creates the child TrieNode if null, and recurses with the first
 /// char removed from the word. If the word length is 0, return.
 /// </summary>
 private void AddWord(TrieNode trieNode, char[] word)
 {
     foreach (var c in word)
     {
         var child = trieNode.GetChild(c);
         if (child == null)
         {
             child = new TrieNode(c);
             trieNode.SetChild(child);
         }
         trieNode = child;
     }
     trieNode.WordCount++;
 }