private string GetItem(string key) { KeywordTrieNode state = this; foreach (var ch in key) { state = state.GetChild(ch); if (state.IsNull()) { return(null); } } return(state.Value); }
public KeywordTrieNode AddChild(char ch, string value = null, bool overwrite = false) { var child = _children.GetOrDefault(ch); if (child.IsNull()) { child = new KeywordTrieNode(value); _children[ch] = child; } else if (overwrite) { child.Value = value; } return(child); }
private void SetItem(string key, string value) { KeywordTrieNode state = this; for (int i = 0; i < key.Length; i++) { if (i < key.Length - 1) { state = state.AddChild(key[i]); } else { var child = state.GetChild(key[i]); state = state.AddChild(key[i], value, true); if (child.IsNull() || !child.HasValue) { Count += 1; } } } }