15 |
|
import java.util.AbstractMap; |
16 |
|
import java.util.Arrays; |
17 |
|
import java.util.Collection; |
18 |
– |
import java.util.Comparator; |
18 |
|
import java.util.ConcurrentModificationException; |
19 |
|
import java.util.Enumeration; |
20 |
|
import java.util.HashMap; |
637 |
|
this.next = next; |
638 |
|
} |
639 |
|
|
640 |
< |
public final K getKey() { return key; } |
641 |
< |
public final V getValue() { return val; } |
642 |
< |
public final int hashCode() { return key.hashCode() ^ val.hashCode(); } |
643 |
< |
public final String toString(){ return key + "=" + val; } |
640 |
> |
public final K getKey() { return key; } |
641 |
> |
public final V getValue() { return val; } |
642 |
> |
public final int hashCode() { return key.hashCode() ^ val.hashCode(); } |
643 |
> |
public final String toString() { return key + "=" + val; } |
644 |
|
public final V setValue(V value) { |
645 |
|
throw new UnsupportedOperationException(); |
646 |
|
} |
2217 |
|
* Must be negative when shifted left by RESIZE_STAMP_SHIFT. |
2218 |
|
*/ |
2219 |
|
static final int resizeStamp(int n) { |
2220 |
< |
return Integer.numberOfLeadingZeros(n) | (1 << (RESIZE_STAMP_BITS - 1)); |
2220 |
> |
return Integer.numberOfLeadingZeros(n) | (1 << (RESIZE_STAMP_BITS - 1)); |
2221 |
|
} |
2222 |
|
|
2223 |
|
/** |
2281 |
|
int rs = resizeStamp(n); |
2282 |
|
if (sc < 0) { |
2283 |
|
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 || |
2284 |
< |
sc == rs + MAX_RESIZERS || (nt = nextTable) == null || |
2285 |
< |
transferIndex <= 0) |
2284 |
> |
sc == rs + MAX_RESIZERS || (nt = nextTable) == null || |
2285 |
> |
transferIndex <= 0) |
2286 |
|
break; |
2287 |
|
if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) |
2288 |
|
transfer(tab, nt); |
2289 |
|
} |
2290 |
|
else if (U.compareAndSwapInt(this, SIZECTL, sc, |
2291 |
< |
(rs << RESIZE_STAMP_SHIFT) + 2)) |
2291 |
> |
(rs << RESIZE_STAMP_SHIFT) + 2)) |
2292 |
|
transfer(tab, null); |
2293 |
|
s = sumCount(); |
2294 |
|
} |
2302 |
|
Node<K,V>[] nextTab; int sc; |
2303 |
|
if (tab != null && (f instanceof ForwardingNode) && |
2304 |
|
(nextTab = ((ForwardingNode<K,V>)f).nextTable) != null) { |
2305 |
< |
int rs = resizeStamp(tab.length); |
2305 |
> |
int rs = resizeStamp(tab.length); |
2306 |
|
while (nextTab == nextTable && table == tab && |
2307 |
< |
(sc = sizeCtl) < 0) { |
2308 |
< |
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 || |
2307 |
> |
(sc = sizeCtl) < 0) { |
2308 |
> |
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 || |
2309 |
|
sc == rs + MAX_RESIZERS || transferIndex <= 0) |
2310 |
< |
break; |
2311 |
< |
if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) { |
2310 |
> |
break; |
2311 |
> |
if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) { |
2312 |
|
transfer(tab, nextTab); |
2313 |
|
break; |
2314 |
|
} |
2349 |
|
else if (tab == table) { |
2350 |
|
int rs = resizeStamp(n); |
2351 |
|
if (sc < 0) { |
2352 |
< |
Node<K,V>[] nt; |
2352 |
> |
Node<K,V>[] nt; |
2353 |
|
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 || |
2354 |
|
sc == rs + MAX_RESIZERS || (nt = nextTable) == null || |
2355 |
|
transferIndex <= 0) |
2358 |
|
transfer(tab, nt); |
2359 |
|
} |
2360 |
|
else if (U.compareAndSwapInt(this, SIZECTL, sc, |
2361 |
< |
(rs << RESIZE_STAMP_SHIFT) + 2)) |
2361 |
> |
(rs << RESIZE_STAMP_SHIFT) + 2)) |
2362 |
|
transfer(tab, null); |
2363 |
|
} |
2364 |
|
} |
2416 |
|
return; |
2417 |
|
} |
2418 |
|
if (U.compareAndSwapInt(this, SIZECTL, sc = sizeCtl, sc - 1)) { |
2419 |
< |
if ((sc - 2) != resizeStamp(n)) |
2419 |
> |
if ((sc - 2) != resizeStamp(n) << RESIZE_STAMP_SHIFT) |
2420 |
|
return; |
2421 |
|
finishing = advance = true; |
2422 |
|
i = n; // recheck before commit |
2532 |
|
} |
2533 |
|
} |
2534 |
|
} |
2535 |
+ |
|
2536 |
|
/** |
2537 |
|
* Returns a list on non-TreeNodes replacing those in given list. |
2538 |
|
*/ |
2578 |
|
final TreeNode<K,V> findTreeNode(int h, Object k, Class<?> kc) { |
2579 |
|
if (k != null) { |
2580 |
|
TreeNode<K,V> p = this; |
2581 |
< |
do { |
2581 |
> |
do { |
2582 |
|
int ph, dir; K pk; TreeNode<K,V> q; |
2583 |
|
TreeNode<K,V> pl = p.left, pr = p.right; |
2584 |
|
if ((ph = p.hash) > h) |
2732 |
|
* using tree comparisons from root, but continues linear |
2733 |
|
* search when lock not available. |
2734 |
|
*/ |
2735 |
< |
final Node<K,V> find(int h, Object k) { |
2735 |
> |
final Node<K,V> find(int h, Object k) { |
2736 |
|
if (k != null) { |
2737 |
< |
for (Node<K,V> e = first; e != null; e = e.next) { |
2737 |
> |
for (Node<K,V> e = first; e != null; ) { |
2738 |
|
int s; K ek; |
2739 |
|
if (((s = lockState) & (WAITER|WRITER)) != 0) { |
2740 |
|
if (e.hash == h && |
2741 |
|
((ek = e.key) == k || (ek != null && k.equals(ek)))) |
2742 |
|
return e; |
2743 |
+ |
e = e.next; |
2744 |
|
} |
2745 |
|
else if (U.compareAndSwapInt(this, LOCKSTATE, s, |
2746 |
|
s + READER)) { |
3027 |
|
|
3028 |
|
static <K,V> TreeNode<K,V> balanceDeletion(TreeNode<K,V> root, |
3029 |
|
TreeNode<K,V> x) { |
3030 |
< |
for (TreeNode<K,V> xp, xpl, xpr;;) { |
3030 |
> |
for (TreeNode<K,V> xp, xpl, xpr;;) { |
3031 |
|
if (x == null || x == root) |
3032 |
|
return root; |
3033 |
|
else if ((xp = x.parent) == null) { |