예제 #1
0
        private IEnumerable <TValue> Walk()
        {
            var nodes       = new AvlTreeKeyValue <TKey, TValue> [this.height];
            var currentNode = this;
            var index       = -1;

            while (!currentNode.IsEmpty || index != -1)
            {
                if (!currentNode.IsEmpty)
                {
                    nodes[++index] = currentNode;
                    currentNode    = currentNode.LeftNode;
                }
                else
                {
                    currentNode = nodes[index--];
                    yield return(currentNode.StoredValue);

                    if (currentNode.Collisions.Length > 0)
                    {
                        for (var i = 0; i < currentNode.Collisions.Length; i++)
                        {
                            yield return(currentNode.Collisions[i]);
                        }
                    }

                    currentNode = currentNode.RightNode;
                }
            }
        }
예제 #2
0
            public AvlTreeEnumerator(AvlTreeKeyValue <TKey, TValue> root)
            {
                this.nodes = new AvlTreeKeyValue <TKey, TValue> [root.height];
                this.root  = root;

                this.Initialize();
            }
예제 #3
0
 private AvlTreeKeyValue(int hash, TKey key, TValue value)
 {
     this.storedKey   = key;
     this.storedHash  = hash;
     this.leftNode    = Empty;
     this.rightNode   = Empty;
     this.storedValue = value;
     this.IsEmpty     = false;
     this.height      = 1;
 }
예제 #4
0
 private void Initialize()
 {
     this.index       = -1;
     this.currentNode = this.root;
     while (!this.currentNode.isEmpty)
     {
         this.nodes[++this.index] = this.currentNode;
         this.currentNode         = this.currentNode.leftNode;
     }
 }
예제 #5
0
 private AvlTreeKeyValue(int hash, TKey key, TValue value, AvlTreeKeyValue <TKey, TValue> left,
                         AvlTreeKeyValue <TKey, TValue> right, ArrayStoreKeyed <TKey, TValue> collisions)
 {
     this.collisions  = collisions;
     this.storedKey   = key;
     this.storedHash  = hash;
     this.leftNode    = left;
     this.rightNode   = right;
     this.storedValue = value;
     this.IsEmpty     = false;
     this.height      = 1 + (left.height > right.height ? left.height : right.height);
 }
예제 #6
0
            public bool MoveNext()
            {
                while (!this.currentNode.isEmpty || this.index != -1)
                {
                    if (!this.currentNode.isEmpty)
                    {
                        this.nodes[++this.index] = this.currentNode;
                        this.currentNode         = this.currentNode.leftNode;
                    }
                    else
                    {
                        this.currentNode = this.nodes[this.index--];
                        this.current     = this.currentNode.storedValue;
                        this.currentNode = this.currentNode.rightNode;
                        return(true);
                    }
                }

                return(false);
            }
예제 #7
0
 /// <summary>
 /// Constructs the <see cref="ConcurrentTree{TKey, TValue}"/>
 /// </summary>
 public ConcurrentTree()
 {
     this.repository = AvlTreeKeyValue <TKey, TValue> .Empty;
 }
예제 #8
0
 private AvlTreeKeyValue <TKey, TValue> SelfCopy(AvlTreeKeyValue <TKey, TValue> left, AvlTreeKeyValue <TKey, TValue> right) =>
 left == this.LeftNode && right == this.RightNode ? this :
 new AvlTreeKeyValue <TKey, TValue>(this.StoredHash, this.StoredKey, this.StoredValue, left, right, this.Collisions);