212 |
|
* @param <K> the type of keys maintained by this map |
213 |
|
* @param <V> the type of mapped values |
214 |
|
*/ |
215 |
< |
public class ConcurrentHashMapV8<K, V> |
216 |
< |
implements ConcurrentMap<K, V>, Serializable { |
215 |
> |
public class ConcurrentHashMapV8<K,V> |
216 |
> |
implements ConcurrentMap<K,V>, Serializable { |
217 |
|
private static final long serialVersionUID = 7249069246763182397L; |
218 |
|
|
219 |
|
/** |
2279 |
|
*/ |
2280 |
|
@SuppressWarnings("serial") static class Traverser<K,V,R> |
2281 |
|
extends CountedCompleter<R> { |
2282 |
< |
final ConcurrentHashMapV8<K, V> map; |
2282 |
> |
final ConcurrentHashMapV8<K,V> map; |
2283 |
|
Node<V> next; // the next entry to use |
2284 |
|
Object nextKey; // cached key field of next |
2285 |
|
V nextVal; // cached val field of next |
2291 |
|
int batch; // split control |
2292 |
|
|
2293 |
|
/** Creates iterator for all entries in the table. */ |
2294 |
< |
Traverser(ConcurrentHashMapV8<K, V> map) { |
2294 |
> |
Traverser(ConcurrentHashMapV8<K,V> map) { |
2295 |
|
this.map = map; |
2296 |
|
} |
2297 |
|
|
2323 |
|
if (e != null) // advance past used/skipped node |
2324 |
|
e = e.next; |
2325 |
|
while (e == null) { // get to next non-null bin |
2326 |
< |
ConcurrentHashMapV8<K, V> m; |
2326 |
> |
ConcurrentHashMapV8<K,V> m; |
2327 |
|
Node<V>[] t; int b, i, n; Object ek; // must use locals |
2328 |
|
if ((t = tab) != null) |
2329 |
|
n = t.length; |
2376 |
|
* anyway. |
2377 |
|
*/ |
2378 |
|
final int preSplit() { |
2379 |
< |
ConcurrentHashMapV8<K, V> m; int b; Node<V>[] t; ForkJoinPool pool; |
2379 |
> |
ConcurrentHashMapV8<K,V> m; int b; Node<V>[] t; ForkJoinPool pool; |
2380 |
|
if ((b = batch) < 0 && (m = map) != null) { // force initialization |
2381 |
|
if ((t = tab) == null && (t = tab = m.table) != null) |
2382 |
|
baseLimit = baseSize = t.length; |
2573 |
|
/** |
2574 |
|
* Tests if the specified object is a key in this table. |
2575 |
|
* |
2576 |
< |
* @param key possible key |
2576 |
> |
* @param key possible key |
2577 |
|
* @return {@code true} if and only if the specified object |
2578 |
|
* is a key in this table, as determined by the |
2579 |
|
* {@code equals} method; {@code false} otherwise |
2687 |
|
* memoized result, as in: |
2688 |
|
* |
2689 |
|
* <pre> {@code |
2690 |
< |
* map.computeIfAbsent(key, new Fun<K, V>() { |
2690 |
> |
* map.computeIfAbsent(key, new Fun<K,V>() { |
2691 |
|
* public V map(K k) { return new Value(f(k)); }});}</pre> |
2692 |
|
* |
2693 |
|
* @param key key with which the specified value is to be associated |
3068 |
|
@SuppressWarnings("serial") static final class KeyIterator<K,V> |
3069 |
|
extends Traverser<K,V,Object> |
3070 |
|
implements Spliterator<K>, Enumeration<K> { |
3071 |
< |
KeyIterator(ConcurrentHashMapV8<K, V> map) { super(map); } |
3072 |
< |
KeyIterator(ConcurrentHashMapV8<K, V> map, Traverser<K,V,Object> it) { |
3071 |
> |
KeyIterator(ConcurrentHashMapV8<K,V> map) { super(map); } |
3072 |
> |
KeyIterator(ConcurrentHashMapV8<K,V> map, Traverser<K,V,Object> it) { |
3073 |
|
super(map, it, -1); |
3074 |
|
} |
3075 |
|
public KeyIterator<K,V> split() { |
3091 |
|
@SuppressWarnings("serial") static final class ValueIterator<K,V> |
3092 |
|
extends Traverser<K,V,Object> |
3093 |
|
implements Spliterator<V>, Enumeration<V> { |
3094 |
< |
ValueIterator(ConcurrentHashMapV8<K, V> map) { super(map); } |
3095 |
< |
ValueIterator(ConcurrentHashMapV8<K, V> map, Traverser<K,V,Object> it) { |
3094 |
> |
ValueIterator(ConcurrentHashMapV8<K,V> map) { super(map); } |
3095 |
> |
ValueIterator(ConcurrentHashMapV8<K,V> map, Traverser<K,V,Object> it) { |
3096 |
|
super(map, it, -1); |
3097 |
|
} |
3098 |
|
public ValueIterator<K,V> split() { |
3115 |
|
@SuppressWarnings("serial") static final class EntryIterator<K,V> |
3116 |
|
extends Traverser<K,V,Object> |
3117 |
|
implements Spliterator<Map.Entry<K,V>> { |
3118 |
< |
EntryIterator(ConcurrentHashMapV8<K, V> map) { super(map); } |
3119 |
< |
EntryIterator(ConcurrentHashMapV8<K, V> map, Traverser<K,V,Object> it) { |
3118 |
> |
EntryIterator(ConcurrentHashMapV8<K,V> map) { super(map); } |
3119 |
> |
EntryIterator(ConcurrentHashMapV8<K,V> map, Traverser<K,V,Object> it) { |
3120 |
|
super(map, it, -1); |
3121 |
|
} |
3122 |
|
public EntryIterator<K,V> split() { |
3138 |
|
/** |
3139 |
|
* Exported Entry for iterators |
3140 |
|
*/ |
3141 |
< |
static final class MapEntry<K,V> implements Map.Entry<K, V> { |
3141 |
> |
static final class MapEntry<K,V> implements Map.Entry<K,V> { |
3142 |
|
final K key; // non-null |
3143 |
|
V val; // non-null |
3144 |
< |
final ConcurrentHashMapV8<K, V> map; |
3145 |
< |
MapEntry(K key, V val, ConcurrentHashMapV8<K, V> map) { |
3144 |
> |
final ConcurrentHashMapV8<K,V> map; |
3145 |
> |
MapEntry(K key, V val, ConcurrentHashMapV8<K,V> map) { |
3146 |
|
this.key = key; |
3147 |
|
this.val = val; |
3148 |
|
this.map = map; |
4578 |
|
/** |
4579 |
|
* Base class for views. |
4580 |
|
*/ |
4581 |
< |
abstract static class CHMView<K, V> { |
4582 |
< |
final ConcurrentHashMapV8<K, V> map; |
4583 |
< |
CHMView(ConcurrentHashMapV8<K, V> map) { this.map = map; } |
4581 |
> |
abstract static class CHMView<K,V> { |
4582 |
> |
final ConcurrentHashMapV8<K,V> map; |
4583 |
> |
CHMView(ConcurrentHashMapV8<K,V> map) { this.map = map; } |
4584 |
|
|
4585 |
|
/** |
4586 |
|
* Returns the map backing this view. |
4722 |
|
implements Set<K>, java.io.Serializable { |
4723 |
|
private static final long serialVersionUID = 7249069246763182397L; |
4724 |
|
private final V value; |
4725 |
< |
KeySetView(ConcurrentHashMapV8<K, V> map, V value) { // non-public |
4725 |
> |
KeySetView(ConcurrentHashMapV8<K,V> map, V value) { // non-public |
4726 |
|
super(map); |
4727 |
|
this.value = value; |
4728 |
|
} |
4756 |
|
V v; |
4757 |
|
if ((v = value) == null) |
4758 |
|
throw new UnsupportedOperationException(); |
4759 |
– |
if (e == null) |
4760 |
– |
throw new NullPointerException(); |
4759 |
|
return map.internalPut(e, v, true) == null; |
4760 |
|
} |
4761 |
|
public boolean addAll(Collection<? extends K> c) { |
4764 |
|
if ((v = value) == null) |
4765 |
|
throw new UnsupportedOperationException(); |
4766 |
|
for (K e : c) { |
4769 |
– |
if (e == null) |
4770 |
– |
throw new NullPointerException(); |
4767 |
|
if (map.internalPut(e, v, true) == null) |
4768 |
|
added = true; |
4769 |
|
} |
4780 |
|
/** |
4781 |
|
* A view of a ConcurrentHashMapV8 as a {@link Collection} of |
4782 |
|
* values, in which additions are disabled. This class cannot be |
4783 |
< |
* directly instantiated. See {@link #values}, |
4783 |
> |
* directly instantiated. See {@link #values()}. |
4784 |
|
* |
4785 |
|
* <p>The view's {@code iterator} is a "weakly consistent" iterator |
4786 |
|
* that will never throw {@link ConcurrentModificationException}, |
4790 |
|
*/ |
4791 |
|
public static final class ValuesView<K,V> extends CHMView<K,V> |
4792 |
|
implements Collection<V> { |
4793 |
< |
ValuesView(ConcurrentHashMapV8<K, V> map) { super(map); } |
4793 |
> |
ValuesView(ConcurrentHashMapV8<K,V> map) { super(map); } |
4794 |
|
public final boolean contains(Object o) { return map.containsValue(o); } |
4795 |
|
public final boolean remove(Object o) { |
4796 |
|
if (o != null) { |
4830 |
|
/** |
4831 |
|
* A view of a ConcurrentHashMapV8 as a {@link Set} of (key, value) |
4832 |
|
* entries. This class cannot be directly instantiated. See |
4833 |
< |
* {@link #entrySet}. |
4833 |
> |
* {@link #entrySet()}. |
4834 |
|
*/ |
4835 |
|
public static final class EntrySetView<K,V> extends CHMView<K,V> |
4836 |
|
implements Set<Map.Entry<K,V>> { |
4837 |
< |
EntrySetView(ConcurrentHashMapV8<K, V> map) { super(map); } |
4837 |
> |
EntrySetView(ConcurrentHashMapV8<K,V> map) { super(map); } |
4838 |
|
public final boolean contains(Object o) { |
4839 |
|
Object k, v, r; Map.Entry<?,?> e; |
4840 |
|
return ((o instanceof Map.Entry) && |
4866 |
|
} |
4867 |
|
|
4868 |
|
public final boolean add(Entry<K,V> e) { |
4869 |
< |
K key = e.getKey(); |
4874 |
< |
V value = e.getValue(); |
4875 |
< |
if (key == null || value == null) |
4876 |
< |
throw new NullPointerException(); |
4877 |
< |
return map.internalPut(key, value, false) == null; |
4869 |
> |
return map.internalPut(e.getKey(), e.getValue(), false) == null; |
4870 |
|
} |
4871 |
|
public final boolean addAll(Collection<? extends Entry<K,V>> c) { |
4872 |
|
boolean added = false; |