private static void Add(SimpleTrieNode <T> node, string s, T value, int index) { while (true) { if (index == s.Length) { node.Leaf = true; node.Value = value; return; } var nextIndex = Char.IsLetter(s, index) ? s[index] - 'a' : 26; var b = node.Next[nextIndex]; if (b != null) { node = b; } else { var go = new SimpleTrieNode <T>(); node.Next[nextIndex] = go; node = go; } index++; } }
public SimpleTrie(IEnumerable <KeyValuePair <string, T> > enumerable) { _root = new SimpleTrieNode <T>(); foreach (var pair in enumerable) { Add(pair); } }
public void Clear() { _root = new SimpleTrieNode <T>(); }
public SimpleTrie() { _root = new SimpleTrieNode <T>(); }
public SimpleTrieNode() { Next = new SimpleTrieNode <T> [27]; Leaf = false; Value = default; }