/// <summary> /// Adds the given string to the trie rooted at this node. /// If the string contains any characters other than lower-case English letters, /// throws an ArgumentException. /// </summary> /// <param name="s">The string to add.</param> /// <returns>The resulting trie.</returns> public ITrie Add(string s) { if (s == "") { _hasEmptyString = true; } else if (s[0] < 'a' || s[0] > 'z') { throw new ArgumentException(); } else { int loc = s[0] - 'a'; if (_children[loc] == null) { _children[loc] = new TrieWithNoChildren(); } _children[loc] = _children[loc].Add(s.Substring(1)); } return(this); }
/// <summary> /// Adds the given string to the trie rooted at this node. /// If the string contains a character that is not a lower-case English /// letter, throws an ArgumentException. /// </summary> /// <param name="s">The string to add.</param> public ITrie Add(string s) { if (s == "") { _hasEmptyString = true; } else { int loc = s[0] - 'a'; if (loc < 0 || loc >= _children.Length) { throw new ArgumentException(); } if (_children[loc] == null) { _children[loc] = new TrieWithNoChildren(); } _children[loc] = _children[loc].Add(s.Substring(1)); } return this; }