@Override public long get(K key) { return map.get(key); }
@Override public void put(K key, long value) { map.put(key, value); }
/** * Increments the primitive value mapped to key by 1 * * @param key the key of the value to increment * @return true if a mapping was found and modified. */ public boolean increment(K key) { return adjustValue(key, (long) 1); }
/** * 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); }
/** * Deletes a key/value pair from the map. * * @param key an <code>Object</code> value * @return an <code>long</code> value or (long)0 if no such mapping exists. */ public long remove(K key) { long prev = (long) 0; int index = index(key); if (index >= 0) { prev = _values[index]; removeAt(index); // clear key,state; adjust size } return prev; }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // NUMBER OF ENTRIES int size = in.readInt(); setUp(size); // ENTRIES while (size-- > 0) { K key = (K) in.readObject(); long val = in.readLong(); put(key, val); } } } // TObjectLongHashMap
/** * 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; }
/** * Compares this map with another map for equality of their stored entries. * * @param other an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean equals(Object other) { if (!(other instanceof TObjectLongHashMap)) { return false; } TObjectLongHashMap that = (TObjectLongHashMap) other; if (that.size() != this.size()) { return false; } return forEachEntry(new EqProcedure(that)); }
/** * 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]; } } }
/** * retrieves the value for <tt>key</tt> * * @param key an <code>Object</code> value * @return the value of <tt>key</tt> or (long)0 if no such mapping exists. */ public long get(K key) { int index = index(key); return index < 0 ? (long) 0 : _values[index]; }
/** * checks for the present of <tt>key</tt> in the keys of the map. * * @param key an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean containsKey(K key) { return contains(key); }
/** * Executes <tt>procedure</tt> for each key in the map. * * @param procedure a <code>TObjectProcedure</code> value * @return false if the loop over the keys terminated because the procedure returned false for * some key. */ public boolean forEachKey(TObjectProcedure<K> procedure) { return forEach(procedure); }
@Override public boolean containsKey(K key) { return map.containsKey(key); }
public void writeExternal(ObjectOutput out) throws IOException { // VERSION out.writeByte(0); // NUMBER OF ENTRIES out.writeInt(_size); // ENTRIES SerializationProcedure writeProcedure = new SerializationProcedure(out); if (!forEachEntry(writeProcedure)) { throw writeProcedure.exception; } }
/** * 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); }
/** * Adjusts the primitive value mapped to key. * * @param key the key of the value to increment * @param amount the amount to adjust the value by. * @return true if a mapping was found and modified. */ public boolean adjustValue(K key, long amount) { int index = index(key); if (index < 0) { return false; } else { _values[index] += amount; return true; } }