示例#1
0
 /// <summary>
 /// Create a node from the given parameters.
 /// </summary>
 /// <param name="Parent">Parent node of this node.</param>
 /// <param name="key">The Key of this node</param>
 /// <param name="children">This node children</param>
 /// <param name="suffixes">This node's suffixes</param>
 public Node(Node parent, Char key, Dictionary<Char, Node> children, List<Word> suffixes)
 {
     this.Key = char.ToLower(key);
     this.Parent = parent;
     this.children = children;
     this.suffixes = suffixes;
 }
示例#2
0
 /// <summary>
 /// Create an empty node with no children and no suffixes.
 /// </summary>
 /// <param name="Parent">Parent node of this node.</param>
 /// <param name="key">The Key of this node</param>
 public Node(Node parent, Char key)
 {
     this.Key = char.ToLower(key);
     this.Parent = parent;
     this.children = new Dictionary<Char, Node>();
     this.suffixes = new List<Word>();
 }
示例#3
0
 /// <summary>
 /// Remove the last character of the currently entered prefix.
 /// </summary>
 public void BackMatch()
 {
     if (current != root)
     {
         current = current.Parent;
         Prefix = Prefix.Substring(0, Prefix.Length - 1);
     }
 }
示例#4
0
 public PrefixMatcher(Node root)
 {
     this.root = this.current = root;
     this.Prefix = "";
 }
示例#5
0
 /// <summary>
 /// Clear the currently entered prefix.
 /// </summary>
 public void ResetMatch()
 {
     this.current = this.root;
     this.Prefix = "";
 }
示例#6
0
 /// <summary>
 /// advance the Matcher to next match
 /// </summary>
 /// <param name="next">the next key to find</param>
 /// <returns>True if the current node has the key, False otherwise</returns>
 public bool NextMatch(char next)
 {
     if (current.hasKey(next))
     {
         current = current.GetChild(next);
         Prefix += next;
         return true;
     }
     return false;
 }
示例#7
0
        private void removeWord(Node node, Word word)
        {
            if (word == null || node == null) return;

            char key;
            Node runner = node;
            if (runner.DecrementSuffix(word))
            {
                while (runner != root)
                {
                    key = runner.Key;
                    runner.RemoveSuffix(word);
                    runner = runner.Parent;
                }
            }
            Matcher.ResetMatch();
        }
示例#8
0
 /// <summary>
 /// Add a child node associated with a Key to this node and return the node.
 /// </summary>
 /// <param name="Key">Key to associated with the child node.</param>
 /// <returns>If given Key already exists then return the existing child node, else return the new child node.</returns>
 public Node addChild(char key)
 {
     key = char.ToLower(key);
     if (children.ContainsKey(key))
         return children[key];
     else
     {
         var newChild = new Node(this, key);
         children.Add(key, newChild);
         return newChild;
     }
 }