GetChild() public method

Get node for given word or prefix if exists
public GetChild ( String wordOrPrefix ) : TrieNode
wordOrPrefix String
return TrieNode
示例#1
0
        /// <summary>
        /// Get node for given char array
        /// </summary>
        public TrieNode GetChild(char[] letters)
        {
            TrieNode currentNode = this;

            for (int i = 0; i < letters.Length && currentNode != null; i++)
            {
                currentNode = currentNode.GetChild(letters[i]);
                if (currentNode == null)
                {
                    return(null);
                }
            }
            return(currentNode);
        }
示例#2
0
        /// <summary>
        /// Append word to the prefix tree
        /// </summary>
        public void AddWord(String word)
        {
            char[]   argChars    = word.ToCharArray();
            TrieNode currentNode = root;

            for (int i = 0; i < argChars.Length; i++)
            {
                if (!currentNode.ContainsChildValue(argChars[i]))
                {
                    currentNode.AddChild(argChars[i], new TrieNode(currentNode.Key + argChars[i]));
                }
                currentNode = currentNode.GetChild(argChars[i]);
            }
            currentNode.IsWord = true;
        }
示例#3
0
 /// <summary>
 /// Get node for given word or prefix
 /// </summary>
 public TrieNode GetNode(String argString)
 {
     return(root.GetChild(argString));
 }