1 |
|
/* |
2 |
< |
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
2 |
> |
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
3 |
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
|
* |
5 |
|
* This code is free software; you can redistribute it and/or modify it |
34 |
|
import java.util.function.BiFunction; |
35 |
|
import java.util.function.Consumer; |
36 |
|
import java.util.function.Function; |
37 |
< |
import jdk.internal.misc.SharedSecrets; |
37 |
> |
// OPENJDK import jdk.internal.access.SharedSecrets; |
38 |
|
|
39 |
|
/** |
40 |
|
* Hash table based implementation of the {@code Map} interface. This |
118 |
|
* should be used only to detect bugs.</i> |
119 |
|
* |
120 |
|
* <p>This class is a member of the |
121 |
< |
* <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework"> |
121 |
> |
* <a href="{@docRoot}/java.base/java/util/package-summary.html#CollectionsFramework"> |
122 |
|
* Java Collections Framework</a>. |
123 |
|
* |
124 |
|
* @param <K> the type of keys maintained by this map |
376 |
|
* Returns a power of two size for the given target capacity. |
377 |
|
*/ |
378 |
|
static final int tableSizeFor(int cap) { |
379 |
< |
int n = cap - 1; |
380 |
< |
n |= n >>> 1; |
381 |
< |
n |= n >>> 2; |
382 |
< |
n |= n >>> 4; |
383 |
< |
n |= n >>> 8; |
384 |
< |
n |= n >>> 16; |
379 |
> |
int n = -1 >>> Integer.numberOfLeadingZeros(cap - 1); |
380 |
|
return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1; |
381 |
|
} |
382 |
|
|
501 |
|
(int)ft : MAXIMUM_CAPACITY); |
502 |
|
if (t > threshold) |
503 |
|
threshold = tableSizeFor(t); |
504 |
+ |
} else { |
505 |
+ |
// Because of linked-list bucket constraints, we cannot |
506 |
+ |
// expand all at once, but can reduce total resize |
507 |
+ |
// effort by repeated doubling now vs later |
508 |
+ |
while (s > threshold && table.length < MAXIMUM_CAPACITY) |
509 |
+ |
resize(); |
510 |
|
} |
511 |
< |
else if (s > threshold) |
511 |
< |
resize(); |
511 |
> |
|
512 |
|
for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) { |
513 |
|
K key = e.getKey(); |
514 |
|
V value = e.getValue(); |
1268 |
|
@Override |
1269 |
|
public V merge(K key, V value, |
1270 |
|
BiFunction<? super V, ? super V, ? extends V> remappingFunction) { |
1271 |
< |
if (value == null) |
1272 |
< |
throw new NullPointerException(); |
1273 |
< |
if (remappingFunction == null) |
1271 |
> |
if (value == null || remappingFunction == null) |
1272 |
|
throw new NullPointerException(); |
1273 |
|
int hash = hash(key); |
1274 |
|
Node<K,V>[] tab; Node<K,V> first; int n, i; |
1311 |
|
else |
1312 |
|
removeNode(hash, key, null, false, true); |
1313 |
|
return v; |
1314 |
< |
} |
1317 |
< |
if (value != null) { |
1314 |
> |
} else { |
1315 |
|
if (t != null) |
1316 |
|
t.putTreeVal(this, tab, hash, key, value); |
1317 |
|
else { |
1322 |
|
++modCount; |
1323 |
|
++size; |
1324 |
|
afterNodeInsertion(true); |
1325 |
+ |
return value; |
1326 |
|
} |
1329 |
– |
return value; |
1327 |
|
} |
1328 |
|
|
1329 |
|
@Override |
1449 |
|
|
1450 |
|
// Check Map.Entry[].class since it's the nearest public type to |
1451 |
|
// what we're actually creating. |
1452 |
< |
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Map.Entry[].class, cap); |
1452 |
> |
jsr166.Platform.checkArray(s, Map.Entry[].class, cap); |
1453 |
|
@SuppressWarnings({"rawtypes","unchecked"}) |
1454 |
|
Node<K,V>[] tab = (Node<K,V>[])new Node[cap]; |
1455 |
|
table = tab; |
2150 |
|
if (replacement != p) { |
2151 |
|
TreeNode<K,V> pp = replacement.parent = p.parent; |
2152 |
|
if (pp == null) |
2153 |
< |
root = replacement; |
2153 |
> |
(root = replacement).red = false; |
2154 |
|
else if (p == pp.left) |
2155 |
|
pp.left = replacement; |
2156 |
|
else |