Exemplo n.º 1
0
 private void GetChars(Node node, IList<char> chars)
 {
     foreach (var child in node.GetChildren())
     {
         if (node.Depth + 1 == child.Depth && !child.Value.Equals(' '))
         {
             chars.Add(child.Value);
         }
         else if(child.Depth > node.Depth + 1)
         {
             return;
         }
     }
 }
Exemplo n.º 2
0
        private void GetTerms(Node node, ICollection<string> words,
            StringBuilder buffer)
        {
            if (node.IsTerm())
            {
                words.Add(buffer.ToString());
            }

            foreach (var child in node.GetChildren())
            {
                buffer.Append(child.Value);
                GetTerms(child, words, buffer);
                buffer.Length--;
            }
        }
Exemplo n.º 3
0
 private void InsertNode(Node node, char[] term)
 {
     foreach (var character in term)
     {
         var child = node.FindChild(character);
         if (child == null)
         {
             child = new Node(character, new Dictionary<char, Node>(), 0, node.Depth + 1);
             node.SetChild(child);
         }
         node = child;
     }
     node.WordCount++;
 }
Exemplo n.º 4
0
 public Trie()
 {
     _root = new Node(' ', new Dictionary<char, Node>(), 0, 0 );
 }
Exemplo n.º 5
0
 public void SetChild(Node node)
 {
     Children[node.Value] = node;
 }