/// <summary> /// Make an iterator that will loop thru the collection in order. /// </summary> /// <param name="dictionary"> /// <see cref="SortedBPlusTreeDictionary<TKey,TValue>"/> /// containing these key/value pairs. /// </param> public Enumerator(SortedBPlusTreeDictionary <TKey, TValue> dictionary) { currentLeaf = null; leafIndex = 0; _version = 0; target = dictionary; Reset(); }
/// <summary> /// Get the node to the immediate left of the node at TreePath. /// </summary> internal SortedBPlusTreeDictionary <TKey, TValue> .Node GetLeftNode() { Debug.Assert(indexStack.Count == nodeStack.Count); for (int depth = indexStack.Count - 2; depth >= 0; --depth) { if (indexStack[depth] > 0) { SortedBPlusTreeDictionary <TKey, TValue> .Node result = ((SortedBPlusTreeDictionary <TKey, TValue> .InternalNode)nodeStack[depth]).GetChild(indexStack[depth] - 1); for (; depth < indexStack.Count - 2; ++depth) { result = ((SortedBPlusTreeDictionary <TKey, TValue> .InternalNode)result).GetChild(result.KeyCount); } return(result); } } return(null); }
/// <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(SortedBPlusTreeDictionary <TKey, TValue> tree, TKey key) { indexStack = new List <int>(); nodeStack = new List <SortedBPlusTreeDictionary <TKey, TValue> .Node>(); SortedBPlusTreeDictionary <TKey, TValue> .Node node = tree._root; for (; ;) { Debug.Assert(node != null); nodeStack.Add(node); int i = node.Search(key, tree._comparer); if (node is SortedBPlusTreeDictionary <TKey, TValue> .LeafNode) { IsFound = i >= 0; if (!IsFound) { i = ~i; } indexStack.Add(i); return; } if (i < 0) { i = ~i; } else { ++i; } indexStack.Add(i); node = ((SortedBPlusTreeDictionary <TKey, TValue> .InternalNode)node).GetChild(i); } }
/// <summary>Adjust tree path to node to the right.</summary> /// <returns>Node to immediate right of current path; <b>null</b> if current path /// at rightmost node.</returns> internal SortedBPlusTreeDictionary <TKey, TValue> .Node TraverseRight() { SortedBPlusTreeDictionary <TKey, TValue> .Node node = null; int height = indexStack.Count; for (; ;) { if (indexStack.Count < 2) { Clear(); node = null; break; } Pop(); node = TopNode; int newIndex = TopNodeIndex + 1; if (newIndex < ((SortedBPlusTreeDictionary <TKey, TValue> .InternalNode)node).ChildCount) { indexStack[indexStack.Count - 1] = newIndex; node = ((SortedBPlusTreeDictionary <TKey, TValue> .InternalNode)node).GetChild(newIndex); for (; ;) { Push(node, 0); if (indexStack.Count >= height) { break; } node = ((SortedBPlusTreeDictionary <TKey, TValue> .InternalNode)node).FirstChild; } break; } } return(node); }
/// <summary> /// Make a new <b>"BPlusTreeDictionary<TKey,TValue>.KeyCollection</b> that /// holds the keys of a <see cref="SortedBPlusTreeDictionary<TKey,TValue>"/>. /// </summary> /// <param name="dictionary"> /// <see cref="SortedBPlusTreeDictionary<TKey,TValue>"/> containing these keys. /// </param> public BPlusTreeKeys(SortedBPlusTreeDictionary <TKey, TValue> dictionary) { this.tree = dictionary; }
// Long form used for 5% performance increase. public BPlusTreeValuesEnumerator(SortedBPlusTreeDictionary <TKey, TValue> tree) { target = tree; Reset(); }
/// <summary> /// Make a new <b>"BPlusTreeDictionary<TKey,TValue>.ValueCollection</b> that /// holds the values of a <see cref="SortedBPlusTreeDictionary<TKey,TValue>"/>. /// </summary> /// <param name="dictionary"> /// <see cref="SortedBPlusTreeDictionary<TKey,TValue>"/> containing these keys. /// </param> public BPlusTreeValues(SortedBPlusTreeDictionary <TKey, TValue> dictionary) { this._target = dictionary; }
/// <summary> /// Make an enumerator that will loop thru the collection in order. /// </summary> /// <param name="dictionary"> /// <see cref="SortedBPlusTreeDictionary<TKey,TValue>"/> /// containing these key/value pairs. /// </param> public BPlusTreeObjectEnumerator(SortedBPlusTreeDictionary <TKey, TValue> dictionary) { target = dictionary; Reset(); }
internal void Push(SortedBPlusTreeDictionary <TKey, TValue> .Node newNode, int newNodeIndex) { nodeStack.Add(newNode); indexStack.Add(newNodeIndex); }