/// <inheritdoc /> public void Add(TKey key, TValue value) { if (head == null) { head = new AVLNode(key, value, this); count++; } else { AVLNode.AddItem(key, value, this, ref count); } }
/// <inheritdoc /> public void Add(KeyValuePair <TKey, TValue> item) { int hash = Math.Abs(item.Key.GetHashCode()) % _size; if (HashMap[hash] == null) { HashMap[hash] = item; _elementCount++; } else if (HashMap[hash] is KeyValuePair <TKey, TValue> ) { if (((KeyValuePair <TKey, TValue>)HashMap[hash]).Key.Equals(item.Key)) { HashMap[hash] = item; } else { AVLNode node = new AVLNode(key: ((KeyValuePair <TKey, TValue>)HashMap[hash]).Key, value: ((KeyValuePair <TKey, TValue>)HashMap[hash]).Value) { head = null }; if (item.Key.CompareTo(((KeyValuePair <TKey, TValue>)HashMap[hash]).Key) < 0) { node.left = new AVLNode(key: item.Key, value: item.Value) { head = node, isLeft = true }; node._depthL = 1; } else { node.right = new AVLNode(key: item.Key, value: item.Value) { head = node, isLeft = false }; node._depthR = 1; } HashMap[hash] = node; _elementCount++; } } else { AVLNode node = (AVLNode)HashMap[hash]; AVLNode.AddItem(node: node, item: item, HashMap: HashMap, hash: hash, elementCount: ref _elementCount); #if TEST AVLNode.checkNodes(node); #endif } }
/// <inheritdoc /> public void Add(TKey key, TValue value) { if (key == null || value == null) { return; } if (head == null) { head = new AVLNode(key, value); count++; } else { AVLNode.AddItem(head, key, value, this, ref count); } }