/// <summary> /// Associates the specified value with the specified key. /// </summary> /// <param name="key">A key to find or create; if key.Offset > 0, bytes /// before that offset are ignored.</param> /// <param name="value">Value to assign to the node, depending on the value /// of mode. On return, value is set to the previous value for the given key.</param> /// <param name="mode">Specifies whether to create an entry if the key is /// not present, and whether to change an existing entry. If mode is Find, /// Set() only retrieves an existing value; it does not change the trie.</param> /// <returns>Returns true if the specified key already existed and false if /// it did not.</returns> protected bool Set(ref KeyWalker key, ref T value, CPMode mode) { if (_head != null) { bool existed = _head.Set(ref key, ref value, ref _head, mode); if (!existed && (mode & CPMode.Create) != (CPMode)0) { _count++; } return(existed); } else if ((mode & CPMode.Create) != (CPMode)0) { Debug.Assert(_count == 0); _head = new CPSNode <T>(ref key, value); _count = 1; } return(false); }
protected void Clear() { _head = null; _count = 0; }