/** * Decreasing the capacity of the map */ private void shrink() { int oldCapacity = keys.length; if (oldCapacity <= LinearProbing.DEFAULT_INITIAL_CAPACITY) return; K oldKeys[] = keys; V oldValues[] = values; int newCapacity = oldCapacity >> 1; @SuppressWarnings("unchecked") K newKeys[] = (K[]) new Object[newCapacity]; @SuppressWarnings("unchecked") V newValues[] = (V[]) new Object[newCapacity]; for (int i = 0; i < oldCapacity; i++) { K key = oldKeys[i]; if (key != null) putKeyValue(newKeys, newValues, key, oldValues[i]); } this.keys = newKeys; this.values = newValues; }
/** * Decreasing the capacity of the map */ private void shrink() { int oldCapacity = keys.length; if (oldCapacity <= LinearProbing.DEFAULT_INITIAL_CAPACITY) return; K oldKeys[] = keys; V oldValues[] = values; int newCapacity = oldCapacity >> 1; @SuppressWarnings("unchecked") K newKeys[] = (K[]) new Object[newCapacity]; @SuppressWarnings("unchecked") V newValues[] = (V[]) new Object[newCapacity]; for (int i = 0; i < oldCapacity; i++) { K key = oldKeys[i]; if (key != null) putKeyValue(newKeys, newValues, key, oldValues[i]); } this.keys = newKeys; this.values = newValues; }
/** * Decreasing the capacity of the map */ private void shrink() { int oldCapacity = keys.length; if (oldCapacity <= LinearProbing.DEFAULT_INITIAL_CAPACITY) return; K oldKeys[] = keys; V oldValues[] = values; int newCapacity = oldCapacity >> 1; @SuppressWarnings("unchecked") K newKeys[] = (K[]) new Object[newCapacity]; @SuppressWarnings("unchecked") V newValues[] = (V[]) new Object[newCapacity]; for (int i = 0; i < oldCapacity; i++) { K key = oldKeys[i]; if (key != null) putKeyValue(newKeys, newValues, key, oldValues[i]); } this.keys = newKeys; this.values = newValues; }
/** * Increasing the capacity of the map */ private void enlarge() { int oldCapacity = keys.length; if (oldCapacity == LinearProbing.MAXIMUM_CAPACITY) throw new IllegalArgumentException( "Map cannot grow beyond capacity: " + LinearProbing.MAXIMUM_CAPACITY); K oldKeys[] = keys; V oldValues[] = values; int newCapacity = oldCapacity << 1; @SuppressWarnings("unchecked") K newKeys[] = (K[]) new Object[newCapacity]; @SuppressWarnings("unchecked") V newValues[] = (V[]) new Object[newCapacity]; for (int i = 0; i < oldCapacity; i++) { K key = oldKeys[i]; if (key != null) putKeyValue(newKeys, newValues, key, oldValues[i]); } this.keys = newKeys; this.values = newValues; }
/** * Increasing the capacity of the map */ private void enlarge() { int oldCapacity = keys.length; if (oldCapacity == LinearProbing.MAXIMUM_CAPACITY) throw new IllegalArgumentException( "Map cannot grow beyond capacity: " + LinearProbing.MAXIMUM_CAPACITY); K oldKeys[] = keys; V oldValues[] = values; int newCapacity = oldCapacity << 1; @SuppressWarnings("unchecked") K newKeys[] = (K[]) new Object[newCapacity]; @SuppressWarnings("unchecked") V newValues[] = (V[]) new Object[newCapacity]; for (int i = 0; i < oldCapacity; i++) { K key = oldKeys[i]; if (key != null) putKeyValue(newKeys, newValues, key, oldValues[i]); } this.keys = newKeys; this.values = newValues; }
/** * Increasing the capacity of the map */ private void enlarge() { int oldCapacity = keys.length; if (oldCapacity == LinearProbing.MAXIMUM_CAPACITY) throw new IllegalArgumentException( "Map cannot grow beyond capacity: " + LinearProbing.MAXIMUM_CAPACITY); K oldKeys[] = keys; V oldValues[] = values; int newCapacity = oldCapacity << 1; @SuppressWarnings("unchecked") K newKeys[] = (K[]) new Object[newCapacity]; @SuppressWarnings("unchecked") V newValues[] = (V[]) new Object[newCapacity]; for (int i = 0; i < oldCapacity; i++) { K key = oldKeys[i]; if (key != null) putKeyValue(newKeys, newValues, key, oldValues[i]); } this.keys = newKeys; this.values = newValues; }
@Override public V put(K key, V value) { if (key == null) throw new NullPointerException(); V result = putKeyValue(keys, values, key, value); if (result == null && ++size == LinearProbing.getUpperSize(keys.length)) enlarge(); return result; }
@Override public V put(K key, V value) { if (key == null) throw new NullPointerException(); V result = putKeyValue(keys, values, key, value); if (result == null && ++size == LinearProbing.getUpperSize(keys.length)) enlarge(); return result; }
@Override public V put(K key, V value) { if (key == null) throw new NullPointerException(); V result = putKeyValue(keys, values, key, value); if (result == null && ++size == LinearProbing.getUpperSize(keys.length)) enlarge(); return result; }