Ejemplo n.º 1
0
 /// <summary>
 /// Create a new TrieNode instance.
 /// </summary>
 /// <param name="character">The character for the TrieNode.</param>
 /// <param name="children">Children of TrieNode.</param>
 /// <param name="isWord">If root TrieNode to this TrieNode is a word.</param>
 /// <param name="wordCount"></param>
 internal TrieNode(char character, IDictionary<char, TrieNode> children,
     int wordCount, TrieNode parent)
 {
     Character = character;
     Children = children;
     WordCount = wordCount;
     Parent = parent;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Create a new TrieNode instance.
 /// </summary>
 /// <param name="character">Character of the TrieNode.</param>
 internal static TrieNode CreateTrieNode(char character,
     TrieNode parent)
 {
     return new TrieNode(character,
         new Dictionary<char, TrieNode>(),
         0,
         parent
         );
 }
Ejemplo n.º 3
0
 internal void SetChild(TrieNode child)
 {
     Children[child.Character] = child;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Recursive method to remove word. Remove only if node does not 
 /// have children and is not a word node and has a parent node.
 /// </summary>
 private void RemoveNode_Recursive(TrieNode rootTrieNode)
 {
     if (Children.Count == 0 // should not have any children
         && !IsWord // should not be a word
         && this != rootTrieNode // do not remove root node
         )
     {
         var parent = Parent;
         Parent.RemoveChild(Character);
         Parent = null;
         parent.RemoveNode_Recursive(rootTrieNode);
     }
 }
Ejemplo n.º 5
0
 internal void RemoveNode(TrieNode rootTrieNode)
 {
     // set this node's word count to 0
     WordCount = 0;
     RemoveNode_Recursive(rootTrieNode);
 }