private PilePointer findPP(string Key) { char[] keys = Key.ToCharArray(); string strKey = ""; PilePointer currentPP = m_Root; PrefixTreeNode current = (PrefixTreeNode)m_Pile.Get(currentPP); bool contains = false; foreach (char charKey in keys) { strKey += charKey; int i = 0; contains = false; for (i = 0; i < current.Children.Length; i++) { if (current.Children[i].Key > charKey) { break; } if (current.Children[i].Key == charKey) { contains = true; break; } } if (i >= current.Children.Length) { break; } currentPP = current.Children[i].ValuePP; current = (PrefixTreeNode)m_Pile.Get(currentPP); } return(contains ? currentPP : default(PilePointer)); }
private T find(string key) { T result = default(T); PilePointer currentPP = findPP(key); if (currentPP != default(PilePointer)) { PrefixTreeNode current = (PrefixTreeNode)m_Pile.Get(currentPP); result = current.ValuePP != default(PilePointer) ? (T)m_Pile.Get(current.ValuePP) : default(T); } return(result); }
private void setValue(string key, T value) { char[] keys = key.ToCharArray(); string strKey = ""; PilePointer currentPP = m_Root; PrefixTreeNode current = (PrefixTreeNode)m_Pile.Get(currentPP); foreach (char charKey in keys) { strKey += charKey; int i = 0; for (i = 0; i < current.Children.Length; i++) { if (current.Children[i].ValuePP == default(PilePointer)) { var tmp = newPrefixTreeNode(); Entry entry = new Entry() { Key = charKey, ValuePP = m_Pile.Put(tmp) }; insertEntry(i, ref current.Children, entry); m_Pile.Put(currentPP, current); } else if (current.Children[i].Key > charKey) { var tmp = newPrefixTreeNode(); Entry entry = new Entry() { Key = charKey, ValuePP = m_Pile.Put(tmp) }; insertEntry(i, ref current.Children, entry); m_Pile.Put(currentPP, current); } if (current.Children[i].Key == charKey) { break; } } currentPP = current.Children[i].ValuePP; current = (PrefixTreeNode)m_Pile.Get(currentPP); } if (current.ValuePP != default(PilePointer)) { m_Pile.Put(current.ValuePP, value); } else { current.ValuePP = m_Pile.Put(value); m_Pile.Put(currentPP, current); m_Count++; } }
public bool Remove(string key) { bool result = false; PilePointer currentPP = findPP(key); if (currentPP != default(PilePointer)) { PrefixTreeNode current = (PrefixTreeNode)m_Pile.Get(currentPP); m_Pile.Delete(current.ValuePP); current.ValuePP = default(PilePointer); m_Pile.Put(currentPP, current); m_Count--; } return(result); }
private void clearItem(PilePointer pp) { if (pp == default(PilePointer)) { return; } PrefixTreeNode current = (PrefixTreeNode)m_Pile.Get(pp); foreach (Entry entry in current.Children) { if (entry.ValuePP != default(PilePointer)) { clearItem(entry.ValuePP); } } if (current.ValuePP != default(PilePointer)) { m_Pile.Delete(current.ValuePP); } m_Pile.Delete(pp); }