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; } } }
public AvlTreeEnumerator(AvlTreeKeyValue <TKey, TValue> root) { this.nodes = new AvlTreeKeyValue <TKey, TValue> [root.height]; this.root = root; this.Initialize(); }
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; }
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; } }
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); }
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); }
/// <summary> /// Constructs the <see cref="ConcurrentTree{TKey, TValue}"/> /// </summary> public ConcurrentTree() { this.repository = AvlTreeKeyValue <TKey, TValue> .Empty; }
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);