@Override public long get(short key) { return map.get(key); }
@Override public long put(short key, long value) { return map.put(key, value); }
public TroveShortLongMap() { this.map = new TShortLongHashMap(); }
/** * Inserts a key/value pair into the map. * * @param key an <code>short</code> value * @param value an <code>long</code> value * @return the previous value associated with <tt>key</tt>, or (short)0 if none was found. */ public long put(short key, long value) { int index = insertionIndex(key); return doPut(key, value, index); }
/** * Deletes a key/value pair from the map. * * @param key an <code>short</code> value * @return an <code>long</code> value, or (short)0 if no mapping for key exists */ public long remove(short key) { long prev = (long) 0; int index = index(key); if (index >= 0) { prev = _values[index]; removeAt(index); // clear key,state; adjust size } return prev; }
/** * 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 TShortLongHashMap)) { return false; } TShortLongHashMap that = (TShortLongHashMap) other; if (that.size() != this.size()) { return false; } return forEachEntry(new EqProcedure(that)); }
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; } }
/** * retrieves the value for <tt>key</tt> * * @param key an <code>short</code> value * @return the value of <tt>key</tt> or (short)0 if no such mapping exists. */ public long get(short key) { int index = index(key); return index < 0 ? (long) 0 : _values[index]; }
/** * 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(short key) { return adjustValue(key, (long) 1); }
/** * checks for the present of <tt>key</tt> in the keys of the map. * * @param key an <code>short</code> value * @return a <code>boolean</code> value */ public boolean containsKey(short key) { return contains(key); }
/** * Executes <tt>procedure</tt> for each key in the map. * * @param procedure a <code>TShortProcedure</code> value * @return false if the loop over the keys terminated because the procedure returned false for * some key. */ public boolean forEachKey(TShortProcedure procedure) { return forEach(procedure); }
@Override public boolean containsKey(short key) { return map.containsKey(key); }
/** * Inserts a key/value pair into the map if the specified key is not already associated with a * value. * * @param key an <code>short</code> value * @param value an <code>long</code> value * @return the previous value associated with <tt>key</tt>, or (short)0 if none was found. */ public long putIfAbsent(short key, long value) { int index = insertionIndex(key); if (index < 0) return _values[-index - 1]; return doPut(key, value, index); }
public int hashCode() { HashProcedure p = new HashProcedure(); forEachEntry(p); return p.getHashCode(); }
/** * 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(short key, long amount) { int index = index(key); if (index < 0) { return false; } else { _values[index] += amount; return true; } }