public new void Clear() { _root = new Node(); _nullEntry = null; _nullValue = null; _entrySet.Clear(); }
public new bool Remove(string key) { if (key == null) { if (_nullEntry != null) { bool retval = _entrySet.Remove(_nullEntry); _nullEntry = null; _nullValue = null; return(retval); } return(false); } Node node = _root; int ni = -1; // look for best match //charLoop: for (int i = 0; i < key.Length; i++) { bool charLoopContinue = false; char c = key[i]; // Advance node if (ni == -1) { ni = 0; node = (node._children == null) ? null : node._children[c % _width]; } // While we have a node to try while (node != null) { // If it is a matching node, goto next char if (node._char[ni] == c || _ignoreCase && node._ochar[ni] == c) { ni++; if (ni == node._char.Length) { ni = -1; } //continue charLoop; charLoopContinue = true; break; } // No char match, so if mid node then no match at all. if (ni > 0) { return(false); } // try next in chain node = node._next; } if (charLoopContinue) { continue; } return(false); } if (ni > 0) { return(false); } if (node != null && node._key == null) { return(false); } bool ret = _entrySet.Remove(node); node._value = null; node._key = null; return(ret); }
public new void Add(string key, object value) { if (key == null) { _nullValue = value; if (_nullEntry == null) { _nullEntry = new NullEntry(this); _entrySet.Add(_nullEntry); } return; } Node node = _root; int ni = -1; Node prev = null; Node parent = null; // look for best match //charLoop: for (int i = 0; i < key.Length; i++) { bool charLoopContinue = false; char c = key[i]; // Advance node if (ni == -1) { parent = node; prev = null; ni = 0; node = (node._children == null) ? null : node._children[c % _width]; } // Loop through a node chain at the same level while (node != null) { // If it is a matching node, goto next char if (node._char[ni] == c || _ignoreCase && node._ochar[ni] == c) { prev = null; ni++; if (ni == node._char.Length) { ni = -1; } //continue charLoop; charLoopContinue = true; break; } // no char match // if the first char, if (ni == 0) { // look along the chain for a char match prev = node; node = node._next; } else { // Split the current node! node.Split(this, ni); i--; ni = -1; //continue charLoop; charLoopContinue = true; break; } } if (charLoopContinue) { continue; } // We have run out of nodes, so as this is a put, make one node = new Node(_ignoreCase, key, i); if (prev != null) // add to end of chain { prev._next = node; } else if (parent != null) // add new child { if (parent._children == null) { parent._children = new Node[_width]; } parent._children[c % _width] = node; int oi = node._ochar[0] % _width; if (node._ochar != null && node._char[0] % _width != oi) { if (parent._children[oi] == null) { parent._children[oi] = node; } else { Node n = parent._children[oi]; while (n._next != null) { n = n._next; } n._next = node; } } } else // this is the root. { _root = node; } break; } // Do we have a node if (node != null) { // Split it if we are in the middle if (ni > 0) { node.Split(this, ni); } node._key = key; node._value = value; _entrySet.Add(node); return; } }