private static void _MatchRecursive(Node node, ISet<string> rtn, string letters, string prefix, int? maxMatches) { if (maxMatches != null && rtn.Count == maxMatches) return; if (node == null) { if (!rtn.Contains(letters)) rtn.Add(letters); return; } letters += node.Letter.ToString(); if (prefix.Length > 0) { if (node.ContainsKey(prefix[0])) { _MatchRecursive(node[prefix[0]], rtn, letters, prefix.Remove(0, 1), maxMatches); } } else { foreach (char key in node.Keys) { _MatchRecursive(node[key], rtn, letters, prefix, maxMatches); } } }
public Trie() { RootNode = new Node { Letter = Node.Root }; }