@Override public V get(long key) { return map.get(key); }
@Override public void put(long key, V value) { map.put(key, value); }
@Override public int size() { return map.size(); }
/** * Inserts a key/value pair into the map. * * @param key an <code>long</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(long key, V value) { int index = insertionIndex(key); return doPut(key, value, index); }
/** * Deletes a key/value pair from the map. * * @param key an <code>long</code> value * @return an <code>Object</code> value or (long)0 if no such mapping exists. */ public V remove(long key) { V prev = null; 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 TLongObjectHashMap)) { return false; } TLongObjectHashMap that = (TLongObjectHashMap) other; if (that.size() != this.size()) { return false; } return forEachEntry(new EqProcedure(that)); }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // NUMBER OF ENTRIES int size = in.readInt(); setUp(size); // ENTRIES while (size-- > 0) { long key = in.readLong(); V val = (V) in.readObject(); put(key, val); } } } // TLongObjectHashMap
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; } }
/** * checks for the present of <tt>key</tt> in the keys of the map. * * @param key an <code>long</code> value * @return a <code>boolean</code> value */ public boolean containsKey(long key) { return contains(key); }
/** * Executes <tt>procedure</tt> for each key in the map. * * @param procedure a <code>TLongProcedure</code> value * @return false if the loop over the keys terminated because the procedure returned false for * some key. */ public boolean forEachKey(TLongProcedure procedure) { return forEach(procedure); }
/** * retrieves the value for <tt>key</tt> * * @param key an <code>long</code> value * @return the value of <tt>key</tt> or (long)0 if no such mapping exists. */ public V get(long key) { int index = index(key); return index < 0 ? null : _values[index]; }
@Override public void clear() { map.clear(); }
@Override public V[] getValues(V[] array) { return map.getValues(array); }
/** * Inserts a key/value pair into the map if the specified key is not already associated with a * value. * * @param key an <code>long</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(long key, V 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(); }
/** * Returns the values of the map. * * @return a <code>Collection</code> value * @see #getValues(Object[]) */ public Object[] getValues() { Object[] vals = new Object[size()]; V[] v = _values; byte[] states = _states; for (int i = v.length, j = 0; i-- > 0; ) { if (states[i] == FULL) { vals[j++] = v[i]; } } return vals; }
/** * returns the keys of the map. * * @return a <code>Set</code> value */ public long[] keys() { long[] keys = new long[size()]; long[] k = _set; byte[] states = _states; for (int i = k.length, j = 0; i-- > 0; ) { if (states[i] == FULL) { keys[j++] = k[i]; } } return keys; }