/** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>long</code> value * @return the previous value associated with <tt>key</tt>, or (long)0 if none was found. */ public long put(K key, long 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>Object</code> value * @param value an <code>long</code> value * @return the previous value associated with <tt>key</tt>, or (long)0 if none was found. */ public long putIfAbsent(K key, long value) { int index = insertionIndex(key); if (index < 0) return _values[-index - 1]; return doPut(key, value, index); }
/** * rehashes the map to the new capacity. * * @param newCapacity an <code>int</code> value */ protected void rehash(int newCapacity) { int oldCapacity = _set.length; K oldKeys[] = (K[]) _set; long oldVals[] = _values; _set = new Object[newCapacity]; Arrays.fill(_set, FREE); _values = new long[newCapacity]; for (int i = oldCapacity; i-- > 0; ) { if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { K o = oldKeys[i]; int index = insertionIndex(o); if (index < 0) { throwObjectContractViolation(_set[(-index - 1)], o); } _set[index] = o; _values[index] = oldVals[i]; } } }
/** * Adjusts the primitive value mapped to the key if the key is present in the map. Otherwise, * the <tt>initial_value</tt> is put in the map. * * @param key the key of the value to increment * @param adjust_amount the amount to adjust the value by * @param put_amount the value put into the map if the key is not initial present * @return the value present in the map after the adjustment or put operation * @since 2.0b1 */ public long adjustOrPutValue(final K key, final long adjust_amount, final long put_amount) { int index = insertionIndex(key); final boolean isNewMapping; final long newValue; if (index < 0) { index = -index - 1; newValue = (_values[index] += adjust_amount); isNewMapping = false; } else { newValue = (_values[index] = put_amount); isNewMapping = true; } K oldKey = (K) _set[index]; _set[index] = key; if (isNewMapping) { postInsertHook(oldKey == FREE); } return newValue; }