/** * rehashes the map to the new capacity. * * @param newCapacity an <code>int</code> value */ protected void rehash(int newCapacity) { int oldCapacity = _set.length; int oldKeys[] = _set; V oldVals[] = _values; byte oldStates[] = _states; _set = new int[newCapacity]; _values = (V[]) new Object[newCapacity]; _states = new byte[newCapacity]; for (int i = oldCapacity; i-- > 0; ) { if (oldStates[i] == FULL) { int o = oldKeys[i]; int index = insertionIndex(o); _set[index] = o; _values[index] = oldVals[i]; _states[index] = FULL; } } }
/** * Inserts a key/value pair into the map. * * @param key an <code>int</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, or {@code null} if none was found. */ public V put(int key, V value) { int index = insertionIndex(key); return doPut(key, value, index); }
/** * Inserts a key/value pair into the map if the specified key is not already associated with a * value. * * @param key an <code>int</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, or {@code null} if none was found. */ public V putIfAbsent(int key, V value) { int index = insertionIndex(key); if (index < 0) return _values[-index - 1]; return doPut(key, value, index); }