Exemple #1
0
 public bool Contains(String word)
 {
     TreeNode tempNode = this.root;
     char[] charArray = word.ToCharArray();
     for (int i = 0; i < charArray.Length; i++)
     {
         TreeNode node = new TreeNode();
         node.Character = charArray[i];
         if (!tempNode.ContainsChild(node))
             return false;
         else
             tempNode = tempNode.GetChildren(charArray[i]);
     }
     if (tempNode.IsWordEnd)
         return true;
     else
         return false;
 }
Exemple #2
0
 public void Add(String word)
 {
     TreeNode tempNode = this.root;
     char[] charArray = word.ToCharArray();
     for (int i = 0; i < charArray.Length; i++)
     {
         TreeNode node = new TreeNode();
         node.Character = charArray[i];
         if (!tempNode.ContainsChild(node))
         {
             tempNode.AppendChild(node);
             tempNode = node;
         }
         else
         {
             tempNode = tempNode.GetChildren(charArray[i]);
         }
     }
     tempNode.IsWordEnd = true;
 }
Exemple #3
0
 public void AppendChild(TreeNode child)
 {
     child.parent = this;
     this.children.Add(child.character, child);
 }
Exemple #4
0
 public TreeNode(char character, bool isWordEnd, TreeNode parent)
 {
     this.character = character;
     this.isWordEnd = isWordEnd;
     this.parent = parent;
 }
Exemple #5
0
 public void RemoveChild(TreeNode child)
 {
     this.children.Remove(child.character);
 }
Exemple #6
0
 public bool ContainsChild(TreeNode child)
 {
     return this.children.ContainsKey(child.character);
 }
        public bool Associate(char nextChar)
        {
            if (currNode.ContainsKey(nextChar))
            {
                step++;
                this.currNode = currNode.GetChildren(nextChar);
                if (currNode.IsWordEnd)
                    this.isOccurWord = true;

                return true;
            }
            else
                return false;
        }
 public AssociateStream()
 {
     tree = WordTreeFactory.GetInstance();
     currNode = Root;
 }
 public void Reset()
 {
     this.step = 0;
     this.currNode = this.Root;
     this.isOccurWord = false;
 }
Exemple #10
0
 public bool Move(string word)
 {
     char[] charArray = word.ToCharArray();
     for (int i = 0; i < charArray.Length; i++)
     {
         if (!Associate(charArray[i]))
         {
             step -= i;
             for(;i > 0;i--)
                 this.currNode = this.currNode.ParentNode;
             return false;
         }
     }
     return this.currNode.IsWordEnd;
 }
Exemple #11
0
 public void DeleteWord(string word)
 {
     Reset();
     if (Move(word) && currNode.IsWordEnd)
     {
         if (currNode.HasChildren)
         {
             currNode.IsWordEnd = false;
         }
         else
         {
             do
             {
                 TreeNode tempNode = currNode.ParentNode;
                 tempNode.RemoveChild(currNode);
                 currNode = tempNode;
             } while (!Root.Equals(currNode) && !currNode.IsWordEnd && !currNode.HasChildren);
         }
     }
     Reset();
 }
Exemple #12
0
 public bool BackToLastWordEnd()
 {
     TreeNode tempNode = currNode;
     do
     {
         tempNode = tempNode.ParentNode;
         step--;
         if (tempNode.IsWordEnd)
         {
             currNode = tempNode;
             return true;
         }
     } while (tempNode.ParentNode != null);
     return false;
 }
Exemple #13
0
 private WordTree()
 {
     root = new TreeNode();
 }