public V put(K key, V value) {
int hash = hash(key);
int index = indexFor(hash, table.length);
for (Entry<K,V> e = table[index]; e != null; e = e.next) {
K k;
if (e.hash == hash && ((k = e.key) == key || (key != null && key.equals(k)))) {
V oldValue = e.value;
e.value = value;
return oldValue;
}
}
modCount++;
addEntry(hash, key, value, index);
return null;
}
static int hash(Object key) {
int h;
return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}
static int indexFor(int h, int length) {
return h & (length-1);
}
void addEntry(int hash, K key, V value, int bucketIndex) {
Entry<K,V> e = table[bucketIndex];
table[bucketIndex] = new Entry<>(hash, key, value, e);
if (size++ >= threshold) {
resize(2 * table.length);
}
}