Comparator<? super K> comparator = this.comparator; Node<K, V>[] table = this.table; int hash = secondaryHash(key.hashCode()); int index = hash & (table.length - 1); Node<K, V> nearest = table[index]; nearest.right = created; rebalance(nearest, true); doubleCapacity();
/** * Returns this map's entry that has the same key and value as {@code * entry}, or null if this map has no such entry. * * <p>This method uses the comparator for key equality rather than {@code * equals}. If this map's comparator isn't consistent with equals (such as * {@code String.CASE_INSENSITIVE_ORDER}), then {@code remove()} and {@code * contains()} will violate the collections API. */ Node<K, V> findByEntry(Entry<?, ?> entry) { Node<K, V> mine = findByObject(entry.getKey()); boolean valuesEqual = mine != null && equal(mine.value, entry.getValue()); return valuesEqual ? mine : null; }
@SuppressWarnings("unchecked") Node<K, V> findByObject(Object key) { try { return key != null ? find((K) key, false) : null; } catch (ClassCastException e) { return null; } }
Node<K, V> removeInternalByKey(Object key) { Node<K, V> node = findByObject(key); if (node != null) { removeInternal(node, true); } return node; }
rotateLeft(node); // AVL right right } else { assert (rightDelta == 1); rotateRight(right); // AVL right left rotateLeft(node); rotateRight(node); // AVL left left } else { assert (leftDelta == -1); rotateLeft(left); // AVL left right rotateRight(node);
removeInternal(adjacent, false); // takes care of rebalance and size-- replaceInParent(node, adjacent); return; } else if (left != null) { replaceInParent(node, left); node.left = null; } else if (right != null) { replaceInParent(node, right); node.right = null; } else { replaceInParent(node, null); rebalance(originalParent, false); size--; modCount++;
@Override public V get(Object key) { Node<K, V> node = findByObject(key); return node != null ? node.value : null; }
/** * Rotates the subtree so that its root's left child is the new root. */ private void rotateRight(Node<K, V> root) { Node<K, V> pivot = root.left; Node<K, V> right = root.right; Node<K, V> pivotLeft = pivot.left; Node<K, V> pivotRight = pivot.right; // move the pivot's right child to the root's left root.left = pivotRight; if (pivotRight != null) { pivotRight.parent = root; } replaceInParent(root, pivot); // move the root to the pivot's right pivot.right = root; root.parent = pivot; // fixup heights root.height = Math.max(right != null ? right.height : 0, pivotRight != null ? pivotRight.height : 0) + 1; pivot.height = Math.max(root.height, pivotLeft != null ? pivotLeft.height : 0) + 1; }
public final void remove() { if (lastReturned == null) { throw new IllegalStateException(); } removeInternal(lastReturned, true); lastReturned = null; expectedModCount = modCount; } }
private void doubleCapacity() { table = doubleCapacity(table); threshold = (table.length / 2) + (table.length / 4); // 3/4 capacity }
removeInternal(adjacent, false); // takes care of rebalance and size-- replaceInParent(node, adjacent); return; } else if (left != null) { replaceInParent(node, left); node.left = null; } else if (right != null) { replaceInParent(node, right); node.right = null; } else { replaceInParent(node, null); rebalance(originalParent, false); size--; modCount++;
Node<K, V> removeInternalByKey(Object key) { Node<K, V> node = findByObject(key); if (node != null) { removeInternal(node, true); } return node; }
rotateLeft(node); // AVL right right } else { assert (rightDelta == 1); rotateRight(right); // AVL right left rotateLeft(node); rotateRight(node); // AVL left left } else { assert (leftDelta == -1); rotateLeft(left); // AVL left right rotateRight(node);
@Override public boolean containsKey(Object key) { return findByObject(key) != null; }
/** * Rotates the subtree so that its root's right child is the new root. */ private void rotateLeft(Node<K, V> root) { Node<K, V> left = root.left; Node<K, V> pivot = root.right; Node<K, V> pivotLeft = pivot.left; Node<K, V> pivotRight = pivot.right; // move the pivot's left child to the root's right root.right = pivotLeft; if (pivotLeft != null) { pivotLeft.parent = root; } replaceInParent(root, pivot); // move the root to the pivot's left pivot.left = root; root.parent = pivot; // fix heights root.height = Math.max(left != null ? left.height : 0, pivotLeft != null ? pivotLeft.height : 0) + 1; pivot.height = Math.max(root.height, pivotRight != null ? pivotRight.height : 0) + 1; }
public final void remove() { if (lastReturned == null) { throw new IllegalStateException(); } removeInternal(lastReturned, true); lastReturned = null; expectedModCount = modCount; } }
private void doubleCapacity() { table = doubleCapacity(table); threshold = (table.length / 2) + (table.length / 4); // 3/4 capacity }
removeInternal(adjacent, false); // takes care of rebalance and size-- replaceInParent(node, adjacent); return; } else if (left != null) { replaceInParent(node, left); node.left = null; } else if (right != null) { replaceInParent(node, right); node.right = null; } else { replaceInParent(node, null); rebalance(originalParent, false); size--; modCount++;
Comparator<? super K> comparator = this.comparator; Node<K, V>[] table = this.table; int hash = secondaryHash(key.hashCode()); int index = hash & (table.length - 1); Node<K, V> nearest = table[index]; nearest.right = created; rebalance(nearest, true); doubleCapacity();
Node<K, V> removeInternalByKey(Object key) { Node<K, V> node = findByObject(key); if (node != null) { removeInternal(node, true); } return node; }