214 |
|
* @param <K> the type of keys maintained by this map |
215 |
|
* @param <V> the type of mapped values |
216 |
|
*/ |
217 |
< |
public class ConcurrentHashMap<K, V> |
218 |
< |
implements ConcurrentMap<K, V>, Serializable { |
217 |
> |
public class ConcurrentHashMap<K,V> |
218 |
> |
implements ConcurrentMap<K,V>, Serializable { |
219 |
|
private static final long serialVersionUID = 7249069246763182397L; |
220 |
|
|
221 |
|
/* |
2188 |
|
*/ |
2189 |
|
@SuppressWarnings("serial") static class Traverser<K,V,R> |
2190 |
|
extends CountedCompleter<R> { |
2191 |
< |
final ConcurrentHashMap<K, V> map; |
2191 |
> |
final ConcurrentHashMap<K,V> map; |
2192 |
|
Node<V> next; // the next entry to use |
2193 |
|
K nextKey; // cached key field of next |
2194 |
|
V nextVal; // cached val field of next |
2199 |
|
int baseSize; // initial table size |
2200 |
|
int batch; // split control |
2201 |
|
/** Creates iterator for all entries in the table. */ |
2202 |
< |
Traverser(ConcurrentHashMap<K, V> map) { |
2202 |
> |
Traverser(ConcurrentHashMap<K,V> map) { |
2203 |
|
this.map = map; |
2204 |
|
Node<V>[] t; |
2205 |
|
if ((t = tab = map.table) != null) |
2258 |
|
if (e != null) // advance past used/skipped node |
2259 |
|
e = e.next; |
2260 |
|
while (e == null) { // get to next non-null bin |
2261 |
< |
ConcurrentHashMap<K, V> m; |
2261 |
> |
ConcurrentHashMap<K,V> m; |
2262 |
|
Node<V>[] t; int b, i, n; Object ek; // must use locals |
2263 |
|
if ((t = tab) != null) |
2264 |
|
n = t.length; |
2935 |
|
@SuppressWarnings("serial") static final class KeyIterator<K,V> |
2936 |
|
extends Traverser<K,V,Object> |
2937 |
|
implements Spliterator<K>, Iterator<K>, Enumeration<K> { |
2938 |
< |
KeyIterator(ConcurrentHashMap<K, V> map) { super(map); } |
2939 |
< |
KeyIterator(ConcurrentHashMap<K, V> map, Traverser<K,V,Object> it) { |
2938 |
> |
KeyIterator(ConcurrentHashMap<K,V> map) { super(map); } |
2939 |
> |
KeyIterator(ConcurrentHashMap<K,V> map, Traverser<K,V,Object> it) { |
2940 |
|
super(map, it); |
2941 |
|
} |
2942 |
|
public KeyIterator<K,V> trySplit() { |
2974 |
|
@SuppressWarnings("serial") static final class ValueIterator<K,V> |
2975 |
|
extends Traverser<K,V,Object> |
2976 |
|
implements Spliterator<V>, Iterator<V>, Enumeration<V> { |
2977 |
< |
ValueIterator(ConcurrentHashMap<K, V> map) { super(map); } |
2978 |
< |
ValueIterator(ConcurrentHashMap<K, V> map, Traverser<K,V,Object> it) { |
2977 |
> |
ValueIterator(ConcurrentHashMap<K,V> map) { super(map); } |
2978 |
> |
ValueIterator(ConcurrentHashMap<K,V> map, Traverser<K,V,Object> it) { |
2979 |
|
super(map, it); |
2980 |
|
} |
2981 |
|
public ValueIterator<K,V> trySplit() { |
3017 |
|
@SuppressWarnings("serial") static final class EntryIterator<K,V> |
3018 |
|
extends Traverser<K,V,Object> |
3019 |
|
implements Spliterator<Map.Entry<K,V>>, Iterator<Map.Entry<K,V>> { |
3020 |
< |
EntryIterator(ConcurrentHashMap<K, V> map) { super(map); } |
3021 |
< |
EntryIterator(ConcurrentHashMap<K, V> map, Traverser<K,V,Object> it) { |
3020 |
> |
EntryIterator(ConcurrentHashMap<K,V> map) { super(map); } |
3021 |
> |
EntryIterator(ConcurrentHashMap<K,V> map, Traverser<K,V,Object> it) { |
3022 |
|
super(map, it); |
3023 |
|
} |
3024 |
|
public EntryIterator<K,V> trySplit() { |
3059 |
|
/** |
3060 |
|
* Exported Entry for iterators |
3061 |
|
*/ |
3062 |
< |
static final class MapEntry<K,V> implements Map.Entry<K, V> { |
3062 |
> |
static final class MapEntry<K,V> implements Map.Entry<K,V> { |
3063 |
|
final K key; // non-null |
3064 |
|
V val; // non-null |
3065 |
< |
final ConcurrentHashMap<K, V> map; |
3066 |
< |
MapEntry(K key, V val, ConcurrentHashMap<K, V> map) { |
3065 |
> |
final ConcurrentHashMap<K,V> map; |
3066 |
> |
MapEntry(K key, V val, ConcurrentHashMap<K,V> map) { |
3067 |
|
this.key = key; |
3068 |
|
this.val = val; |
3069 |
|
this.map = map; |
4465 |
|
abstract static class CHMCollectionView<K, V, E> |
4466 |
|
implements Collection<E>, java.io.Serializable { |
4467 |
|
private static final long serialVersionUID = 7249069246763182397L; |
4468 |
< |
final ConcurrentHashMap<K, V> map; |
4469 |
< |
CHMCollectionView(ConcurrentHashMap<K, V> map) { this.map = map; } |
4468 |
> |
final ConcurrentHashMap<K,V> map; |
4469 |
> |
CHMCollectionView(ConcurrentHashMap<K,V> map) { this.map = map; } |
4470 |
|
|
4471 |
|
/** |
4472 |
|
* Returns the map backing this view. |
4616 |
|
extends CHMCollectionView<K, V, E> |
4617 |
|
implements Set<E>, java.io.Serializable { |
4618 |
|
private static final long serialVersionUID = 7249069246763182397L; |
4619 |
< |
CHMSetView(ConcurrentHashMap<K, V> map) { super(map); } |
4619 |
> |
CHMSetView(ConcurrentHashMap<K,V> map) { super(map); } |
4620 |
|
|
4621 |
|
// Implement Set API |
4622 |
|
|
4658 |
|
implements Set<K>, java.io.Serializable { |
4659 |
|
private static final long serialVersionUID = 7249069246763182397L; |
4660 |
|
private final V value; |
4661 |
< |
KeySetView(ConcurrentHashMap<K, V> map, V value) { // non-public |
4661 |
> |
KeySetView(ConcurrentHashMap<K,V> map, V value) { // non-public |
4662 |
|
super(map); |
4663 |
|
this.value = value; |
4664 |
|
} |
4758 |
|
extends CHMCollectionView<K,V,V> |
4759 |
|
implements Collection<V>, java.io.Serializable { |
4760 |
|
private static final long serialVersionUID = 2249069246763182397L; |
4761 |
< |
ValuesView(ConcurrentHashMap<K, V> map) { super(map); } |
4761 |
> |
ValuesView(ConcurrentHashMap<K,V> map) { super(map); } |
4762 |
|
public final boolean contains(Object o) { |
4763 |
|
return map.containsValue(o); |
4764 |
|
} |
4810 |
|
extends CHMSetView<K,V,Map.Entry<K,V>> |
4811 |
|
implements Set<Map.Entry<K,V>>, java.io.Serializable { |
4812 |
|
private static final long serialVersionUID = 2249069246763182397L; |
4813 |
< |
EntrySetView(ConcurrentHashMap<K, V> map) { super(map); } |
4813 |
> |
EntrySetView(ConcurrentHashMap<K,V> map) { super(map); } |
4814 |
|
|
4815 |
|
public final boolean contains(Object o) { |
4816 |
|
Object k, v, r; Map.Entry<?,?> e; |