Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Make a new <b>"BtreeDictionary&lt;TKey,TValue&gt;.KeyCollection</b> that
 /// holds the keys of a <see cref="BtreeDictionary&lt;TKey,TValue&gt;"/>.
 /// </summary>
 /// <param name="dictionary">
 /// <see cref="BtreeDictionary&lt;TKey,TValue&gt;"/> containing these keys.
 /// </param>
 public BtreeKeys(BtreeDictionary <TKey, TValue> dictionary)
 {
     this.tree = dictionary;
 }
Exemplo n.º 3
0
 // Long form used for 5% performance increase.
 public BtreeKeysEnumerator(BtreeDictionary <TKey, TValue> tree)
 {
     target = tree;
     Reset();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Make an iterator that will loop thru the collection in order.
 /// </summary>
 /// <param name="dictionary">
 /// <see cref="BtreeDictionary&lt;TKey,TValue&gt;"/>
 /// containing these key/value pairs.
 /// </param>
 public BtreeEnumerator(BtreeDictionary <TKey, TValue> dictionary)
 {
     target = dictionary;
     Reset();
 }