Пример #1
0
 public void Add(string word, int index = 0)
 {
     if (word.Length == index + 1)
     {
         IsWord = true;
     }
     else
     {
         var      next = word[index + 1];
         WordNode child;
         if (!Children.TryGetValue(next, out child))
         {
             Children[next] = new WordNode(next);
         }
         else if (Children[next].Children.Count == 0)
         {
             Children[next] = new WordNode(next)
             {
                 IsWord = true
             }
         }
         ;
         Children[next].Add(word, index + 1);
     }
 }
Пример #2
0
 private void Build(string[] words)
 {
     foreach (var word in words)
     {
         var first = word[0];
         WordNode child;
         if (!Children.TryGetValue(first, out child))
         {
             child = new WordNode(first);
             Children.Add(first, child);
         }
         child.Add(word);
     }
 }
Пример #3
0
 private void Build(string[] words)
 {
     foreach (var word in words)
     {
         var      first = word[0];
         WordNode child;
         if (!Children.TryGetValue(first, out child))
         {
             child = new WordNode(first);
             Children.Add(first, child);
         }
         child.Add(word);
     }
 }
Пример #4
0
 public void Add(string word, int index = 0)
 {
     if (word.Length == index + 1)
         IsWord = true;
     else
     {
         var next = word[index + 1];
         WordNode child;
         if (!Children.TryGetValue(next, out child))
             Children[next] = new WordNode(next);
         else if (Children[next].Children.Count == 0)
             Children[next] = new WordNode(next) { IsWord = true };
         Children[next].Add(word, index + 1);
     }
 }