clear out the hash table after resizing, and check for table modification in reads

This commit is contained in:
Arya Asemanfar 2012-12-06 10:36:13 -08:00 committed by Norman Maurer
parent 7aa2cfad65
commit 9dd0756d7a

View File

@ -316,7 +316,11 @@ public final class ConcurrentIdentityHashMap<K, V> extends AbstractMap<K, V>
V get(Object key, int hash) {
if (count != 0) { // read-volatile
HashEntry<K, V> e = getFirst(hash);
HashEntry<K, V>[] tab = table;
HashEntry<K, V> e = tab[hash & tab.length - 1];
if (tab != table) {
return get(key, hash);
}
while (e != null) {
if (e.hash == hash && keyEq(key, e.key())) {
V opaque = e.value();
@ -334,7 +338,11 @@ public final class ConcurrentIdentityHashMap<K, V> extends AbstractMap<K, V>
boolean containsKey(Object key, int hash) {
if (count != 0) { // read-volatile
HashEntry<K, V> e = getFirst(hash);
HashEntry<K, V>[] tab = table;
HashEntry<K, V> e = tab[hash & tab.length - 1];
if (tab != table) {
return containsKey(key, hash);
}
while (e != null) {
if (e.hash == hash && keyEq(key, e.key())) {
return true;
@ -363,6 +371,9 @@ public final class ConcurrentIdentityHashMap<K, V> extends AbstractMap<K, V>
}
}
}
if (table != tab) {
return containsValue(value);
}
}
return false;
}
@ -504,6 +515,9 @@ public final class ConcurrentIdentityHashMap<K, V> extends AbstractMap<K, V>
}
}
table = newTable;
for (int i = 0; i < oldCapacity; ++i) {
oldTable[i] = null;
}
return reduce;
}