/// <summary>Perform search and store each level of path on the stack.</summary> /// <param name="tree">Tree to search.</param> /// <param name="key">Value to find.</param> internal TreePath(BtreeDictionary <TKey, TValue> tree, TKey key) { indexStack = new List <int>(); nodeStack = new List <Node <TKey> >(); Node <TKey> node = tree.root; for (;;) { Debug.Assert(node != null); nodeStack.Add(node); int i = node.Search(key, tree.comparer); if (node is Leaf <TKey, TValue> ) { IsFound = i >= 0; if (!IsFound) { i = ~i; } indexStack.Add(i); return; } if (i < 0) { i = ~i; } else { ++i; } indexStack.Add(i); node = ((Branch <TKey>)node).GetChild(i); } }
/// <summary> /// Make a new <b>"BtreeDictionary<TKey,TValue>.KeyCollection</b> that /// holds the keys of a <see cref="BtreeDictionary<TKey,TValue>"/>. /// </summary> /// <param name="dictionary"> /// <see cref="BtreeDictionary<TKey,TValue>"/> containing these keys. /// </param> public BtreeKeys(BtreeDictionary <TKey, TValue> dictionary) { this.tree = dictionary; }
// Long form used for 5% performance increase. public BtreeKeysEnumerator(BtreeDictionary <TKey, TValue> tree) { target = tree; Reset(); }
/// <summary> /// Make an iterator that will loop thru the collection in order. /// </summary> /// <param name="dictionary"> /// <see cref="BtreeDictionary<TKey,TValue>"/> /// containing these key/value pairs. /// </param> public BtreeEnumerator(BtreeDictionary <TKey, TValue> dictionary) { target = dictionary; Reset(); }