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; |
114 |
|
* objects do not support method {@code setValue}. |
115 |
|
* |
116 |
|
* <ul> |
117 |
< |
* <li> forEach: Perform a given action on each element. |
117 |
> |
* <li>forEach: Perform a given action on each element. |
118 |
|
* A variant form applies a given transformation on each element |
119 |
< |
* before performing the action.</li> |
119 |
> |
* before performing the action. |
120 |
|
* |
121 |
< |
* <li> search: Return the first available non-null result of |
121 |
> |
* <li>search: Return the first available non-null result of |
122 |
|
* applying a given function on each element; skipping further |
123 |
< |
* search when a result is found.</li> |
123 |
> |
* search when a result is found. |
124 |
|
* |
125 |
< |
* <li> reduce: Accumulate each element. The supplied reduction |
125 |
> |
* <li>reduce: Accumulate each element. The supplied reduction |
126 |
|
* function cannot rely on ordering (more formally, it should be |
127 |
|
* both associative and commutative). There are five variants: |
128 |
|
* |
129 |
|
* <ul> |
130 |
|
* |
131 |
< |
* <li> Plain reductions. (There is not a form of this method for |
131 |
> |
* <li>Plain reductions. (There is not a form of this method for |
132 |
|
* (key, value) function arguments since there is no corresponding |
133 |
< |
* return type.)</li> |
133 |
> |
* return type.) |
134 |
|
* |
135 |
< |
* <li> Mapped reductions that accumulate the results of a given |
136 |
< |
* function applied to each element.</li> |
135 |
> |
* <li>Mapped reductions that accumulate the results of a given |
136 |
> |
* function applied to each element. |
137 |
|
* |
138 |
< |
* <li> Reductions to scalar doubles, longs, and ints, using a |
139 |
< |
* given basis value.</li> |
138 |
> |
* <li>Reductions to scalar doubles, longs, and ints, using a |
139 |
> |
* given basis value. |
140 |
|
* |
141 |
|
* </ul> |
143 |
– |
* </li> |
142 |
|
* </ul> |
143 |
|
* |
144 |
|
* <p>These bulk operations accept a {@code parallelismThreshold} |
487 |
|
* |
488 |
|
* Maintaining API and serialization compatibility with previous |
489 |
|
* versions of this class introduces several oddities. Mainly: We |
490 |
< |
* leave untouched but unused constructor arguments refering to |
490 |
> |
* leave untouched but unused constructor arguments referring to |
491 |
|
* concurrencyLevel. We accept a loadFactor constructor argument, |
492 |
|
* but apply it only to initial table capacity (which is the only |
493 |
|
* time that we can guarantee to honor it.) We also declare an |
636 |
|
this.next = next; |
637 |
|
} |
638 |
|
|
639 |
< |
public final K getKey() { return key; } |
640 |
< |
public final V getValue() { return val; } |
641 |
< |
public final int hashCode() { return key.hashCode() ^ val.hashCode(); } |
642 |
< |
public final String toString(){ return key + "=" + val; } |
639 |
> |
public final K getKey() { return key; } |
640 |
> |
public final V getValue() { return val; } |
641 |
> |
public final int hashCode() { return key.hashCode() ^ val.hashCode(); } |
642 |
> |
public final String toString() { return key + "=" + val; } |
643 |
|
public final V setValue(V value) { |
644 |
|
throw new UnsupportedOperationException(); |
645 |
|
} |
2216 |
|
* Must be negative when shifted left by RESIZE_STAMP_SHIFT. |
2217 |
|
*/ |
2218 |
|
static final int resizeStamp(int n) { |
2219 |
< |
return Integer.numberOfLeadingZeros(n) | (1 << (RESIZE_STAMP_BITS - 1)); |
2219 |
> |
return Integer.numberOfLeadingZeros(n) | (1 << (RESIZE_STAMP_BITS - 1)); |
2220 |
|
} |
2221 |
|
|
2222 |
|
/** |
2280 |
|
int rs = resizeStamp(n); |
2281 |
|
if (sc < 0) { |
2282 |
|
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 || |
2283 |
< |
sc == rs + MAX_RESIZERS || (nt = nextTable) == null || |
2284 |
< |
transferIndex <= 0) |
2283 |
> |
sc == rs + MAX_RESIZERS || (nt = nextTable) == null || |
2284 |
> |
transferIndex <= 0) |
2285 |
|
break; |
2286 |
|
if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) |
2287 |
|
transfer(tab, nt); |
2288 |
|
} |
2289 |
|
else if (U.compareAndSwapInt(this, SIZECTL, sc, |
2290 |
< |
(rs << RESIZE_STAMP_SHIFT) + 2)) |
2290 |
> |
(rs << RESIZE_STAMP_SHIFT) + 2)) |
2291 |
|
transfer(tab, null); |
2292 |
|
s = sumCount(); |
2293 |
|
} |
2301 |
|
Node<K,V>[] nextTab; int sc; |
2302 |
|
if (tab != null && (f instanceof ForwardingNode) && |
2303 |
|
(nextTab = ((ForwardingNode<K,V>)f).nextTable) != null) { |
2304 |
< |
int rs = resizeStamp(tab.length); |
2304 |
> |
int rs = resizeStamp(tab.length); |
2305 |
|
while (nextTab == nextTable && table == tab && |
2306 |
< |
(sc = sizeCtl) < 0) { |
2307 |
< |
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 || |
2306 |
> |
(sc = sizeCtl) < 0) { |
2307 |
> |
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 || |
2308 |
|
sc == rs + MAX_RESIZERS || transferIndex <= 0) |
2309 |
< |
break; |
2310 |
< |
if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) { |
2309 |
> |
break; |
2310 |
> |
if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) { |
2311 |
|
transfer(tab, nextTab); |
2312 |
|
break; |
2313 |
|
} |
2348 |
|
else if (tab == table) { |
2349 |
|
int rs = resizeStamp(n); |
2350 |
|
if (sc < 0) { |
2351 |
< |
Node<K,V>[] nt; |
2351 |
> |
Node<K,V>[] nt; |
2352 |
|
if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 || |
2353 |
|
sc == rs + MAX_RESIZERS || (nt = nextTable) == null || |
2354 |
|
transferIndex <= 0) |
2357 |
|
transfer(tab, nt); |
2358 |
|
} |
2359 |
|
else if (U.compareAndSwapInt(this, SIZECTL, sc, |
2360 |
< |
(rs << RESIZE_STAMP_SHIFT) + 2)) |
2360 |
> |
(rs << RESIZE_STAMP_SHIFT) + 2)) |
2361 |
|
transfer(tab, null); |
2362 |
|
} |
2363 |
|
} |
2415 |
|
return; |
2416 |
|
} |
2417 |
|
if (U.compareAndSwapInt(this, SIZECTL, sc = sizeCtl, sc - 1)) { |
2418 |
< |
if ((sc - 2) != resizeStamp(n)) |
2418 |
> |
if ((sc - 2) != resizeStamp(n) << RESIZE_STAMP_SHIFT) |
2419 |
|
return; |
2420 |
|
finishing = advance = true; |
2421 |
|
i = n; // recheck before commit |
2531 |
|
} |
2532 |
|
} |
2533 |
|
} |
2534 |
+ |
|
2535 |
|
/** |
2536 |
< |
* Returns a list on non-TreeNodes replacing those in given list. |
2536 |
> |
* Returns a list of non-TreeNodes replacing those in given list. |
2537 |
|
*/ |
2538 |
|
static <K,V> Node<K,V> untreeify(Node<K,V> b) { |
2539 |
|
Node<K,V> hd = null, tl = null; |
2577 |
|
final TreeNode<K,V> findTreeNode(int h, Object k, Class<?> kc) { |
2578 |
|
if (k != null) { |
2579 |
|
TreeNode<K,V> p = this; |
2580 |
< |
do { |
2580 |
> |
do { |
2581 |
|
int ph, dir; K pk; TreeNode<K,V> q; |
2582 |
|
TreeNode<K,V> pl = p.left, pr = p.right; |
2583 |
|
if ((ph = p.hash) > h) |
2731 |
|
* using tree comparisons from root, but continues linear |
2732 |
|
* search when lock not available. |
2733 |
|
*/ |
2734 |
< |
final Node<K,V> find(int h, Object k) { |
2734 |
> |
final Node<K,V> find(int h, Object k) { |
2735 |
|
if (k != null) { |
2736 |
< |
for (Node<K,V> e = first; e != null; e = e.next) { |
2736 |
> |
for (Node<K,V> e = first; e != null; ) { |
2737 |
|
int s; K ek; |
2738 |
|
if (((s = lockState) & (WAITER|WRITER)) != 0) { |
2739 |
|
if (e.hash == h && |
2740 |
|
((ek = e.key) == k || (ek != null && k.equals(ek)))) |
2741 |
|
return e; |
2742 |
+ |
e = e.next; |
2743 |
|
} |
2744 |
|
else if (U.compareAndSwapInt(this, LOCKSTATE, s, |
2745 |
|
s + READER)) { |
3026 |
|
|
3027 |
|
static <K,V> TreeNode<K,V> balanceDeletion(TreeNode<K,V> root, |
3028 |
|
TreeNode<K,V> x) { |
3029 |
< |
for (TreeNode<K,V> xp, xpl, xpr;;) { |
3029 |
> |
for (TreeNode<K,V> xp, xpl, xpr;;) { |
3030 |
|
if (x == null || x == root) |
3031 |
|
return root; |
3032 |
|
else if ((xp = x.parent) == null) { |