Example #1
0
 public void AddWord(string origWord)
 {
     char firstChar = origWord[0];
     byte firstDigit;
     if (! WordTree.LetterToDigit.TryGetValue(firstChar, out firstDigit)) { return; }
     if (! children.ContainsKey(firstDigit)) { children[firstDigit] = new WordTreeNode(); }
     children[firstDigit].addWordImpl(origWord, origWord.Substring(1));
 }
Example #2
0
        public void AddWord(string origWord)
        {
            char firstChar = origWord[0];
            byte firstDigit;

            if (!WordTree.LetterToDigit.TryGetValue(firstChar, out firstDigit))
            {
                return;
            }
            if (!children.ContainsKey(firstDigit))
            {
                children[firstDigit] = new WordTreeNode();
            }
            children[firstDigit].addWordImpl(origWord, origWord.Substring(1));
        }
Example #3
0
        public IEnumerable <string> GetAllWords()
        {
            Stack <WordTreeNode> nodes = new Stack <WordTreeNode>();  // Depth first

            nodes.Push(RootNode);
            while (nodes.Count() > 0)
            {
                WordTreeNode node = nodes.Pop();
                foreach (string word in node.GetWords())
                {
                    yield return(word);
                }
                foreach (WordTreeNode child in node.GetChildren())
                {
                    nodes.Push(child);
                }
            }
        }
Example #4
0
        private void addWordImpl(string origWord, string partialWord)
        {
            if (partialWord == String.Empty)
            {
                this.words.Add(origWord);
                return;
            }
            char nextChar = partialWord[0];
            byte nextDigit;

            if (!WordTree.LetterToDigit.TryGetValue(nextChar, out nextDigit))
            {
                return;
            }
            if (!children.ContainsKey(nextDigit))
            {
                children[nextDigit] = new WordTreeNode();
            }
            children[nextDigit].addWordImpl(origWord, partialWord.Substring(1));
        }
Example #5
0
 private void addWordImpl(string origWord, string partialWord)
 {
     if (partialWord == String.Empty)
     {
         this.words.Add(origWord);
         return;
     }
     char nextChar = partialWord[0];
     byte nextDigit;
     if (! WordTree.LetterToDigit.TryGetValue(nextChar, out nextDigit)) { return; }
     if (! children.ContainsKey(nextDigit)) { children[nextDigit] = new WordTreeNode(); }
     children[nextDigit].addWordImpl(origWord, partialWord.Substring(1));
 }
Example #6
0
 public WordTree()
 {
     rootNode = new WordTreeNode();
 }
Example #7
0
 public WordTree()
 {
     rootNode = new WordTreeNode();
 }