Package com.google.common.collect
Class MapMakerInternalMap<K,V,E extends MapMakerInternalMap.InternalEntry<K,V,E>,S extends MapMakerInternalMap.Segment<K,V,E,S>>
java.lang.Object
java.util.AbstractMap<K,V>
com.google.common.collect.MapMakerInternalMap<K,V,E,S>
- Type Parameters:
K- the type of the keys in the mapV- the type of the values in the mapE- the type of theMapMakerInternalMap.InternalEntryentry implementation used internallyS- the type of theMapMakerInternalMap.Segmententry implementation used internally
- All Implemented Interfaces:
Serializable,ConcurrentMap<K,,V> Map<K,V>
class MapMakerInternalMap<K,V,E extends MapMakerInternalMap.InternalEntry<K,V,E>,S extends MapMakerInternalMap.Segment<K,V,E,S>>
extends AbstractMap<K,V>
implements ConcurrentMap<K,V>, Serializable
The concurrent hash map implementation built by
MapMaker.
This implementation is heavily derived from revision 1.96 of ConcurrentHashMap.java.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classThe actual object that gets serialized.(package private) static classBase class forMapMakerInternalMap.InternalEntryimplementations for strong keys.(package private) static classBase class forMapMakerInternalMap.InternalEntryimplementations for weak keys.(package private) static final class(package private) static final classA dummy implementation ofMapMakerInternalMap.InternalEntry, solely for use in the type signature ofUNSET_WEAK_VALUE_REFERENCEbelow.(package private) final class(package private) final class(package private) class(package private) static interfaceAn entry in a hash table of aMapMakerInternalMap.Segment.(package private) static interfaceMapMakerInternalMap.InternalEntryHelper<K,V, E extends MapMakerInternalMap.InternalEntry<K, V, E>, S extends MapMakerInternalMap.Segment<K, V, E, S>> A helper object for operating onMapMakerInternalMap.InternalEntryinstances in a type-safe and efficient manner.(package private) final class(package private) final class(package private) static classMapMakerInternalMap.Segment<K,V, E extends MapMakerInternalMap.InternalEntry<K, V, E>, S extends MapMakerInternalMap.Segment<K, V, E, S>> Segments are specialized versions of hash tables.private static final classThe actual object that gets serialized.(package private) static enum(package private) static classConcrete implementation ofMapMakerInternalMap.InternalEntryfor strong keys andMapMaker.Dummyvalues.(package private) static final classConcrete implementation ofMapMakerInternalMap.Segmentfor strong keys andMapMaker.Dummyvalues.(package private) static classConcrete implementation ofMapMakerInternalMap.InternalEntryfor strong keys and strong values.(package private) static final classConcrete implementation ofMapMakerInternalMap.Segmentfor strong keys and strong values.(package private) static classConcrete implementation ofMapMakerInternalMap.InternalEntryfor strong keys and weak values.(package private) static final classConcrete implementation ofMapMakerInternalMap.Segmentfor strong keys and weak values.(package private) static interfaceMarker interface forMapMakerInternalMap.InternalEntryimplementations for strong values.(package private) final class(package private) final class(package private) static classConcrete implementation ofMapMakerInternalMap.InternalEntryfor weak keys andMapMaker.Dummyvalues.(package private) static final classConcrete implementation ofMapMakerInternalMap.Segmentfor weak keys andMapMaker.Dummyvalues.(package private) static classConcrete implementation ofMapMakerInternalMap.InternalEntryfor weak keys and strong values.(package private) static final classConcrete implementation ofMapMakerInternalMap.Segmentfor weak keys and strong values.(package private) static classConcrete implementation ofMapMakerInternalMap.InternalEntryfor weak keys and weak values.(package private) static final classConcrete implementation ofMapMakerInternalMap.Segmentfor weak keys and weak values.(package private) static interfaceMarker interface forMapMakerInternalMap.InternalEntryimplementations for weak values.(package private) static interfaceA weakly referenced value that also has a reference to its containing entry.(package private) static final classConcrete implementation ofMapMakerInternalMap.WeakValueReference.(package private) final classCustom Entry class used by EntryIterator.next(), that relays setValue changes to the underlying map.Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final intThe concurrency level.(package private) static final intNumber of (unsynchronized) retries in the containsValue method.(package private) static final intMaximum number of entries to be drained in a single cleanup run.(package private) static final intNumber of cache access operations that can be buffered per segment before the cache's recency ordering information is updated.(package private) final MapMakerInternalMap.InternalEntryHelper<K, V, E, S> Strategy for handling entries and segments in a type-safe and efficient manner.(package private) final Equivalence<Object> Strategy for comparing keys.(package private) static final intThe maximum number of segments to allow; used to bound constructor arguments.(package private) static final intThe maximum capacity, used if a higher value is implicitly specified by either of the constructors with arguments.(package private) final intMask value for indexing into segments.(package private) final MapMakerInternalMap.Segment<K,V, E, S>[] The segments, each of which is a specialized hash table.(package private) final intShift value for indexing within segments.private static final long(package private) static final MapMakerInternalMap.WeakValueReference<Object, Object, MapMakerInternalMap.DummyInternalEntry> A singletonMapMakerInternalMap.WeakValueReferenceused to denote an unset value in an entry with weak values.(package private) Collection<V> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateMapMakerInternalMap(MapMaker builder, MapMakerInternalMap.InternalEntryHelper<K, V, E, S> entryHelper) Creates a new, empty map with the specified strategy, initial capacity and concurrency level. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(Object key) booleancontainsValue(Object value) (package private) EThis method is a convenience for testing.(package private) static <K,V> MapMakerInternalMap <K, V, ? extends MapMakerInternalMap.InternalEntry<K, V, ?>, ?> Returns a freshMapMakerInternalMapas specified by the givenbuilder.(package private) MapMakerInternalMap.Segment<K, V, E, S> createSegment(int initialCapacity) (package private) static <K> MapMakerInternalMap<K, MapMaker.Dummy, ? extends MapMakerInternalMap.InternalEntry<K, MapMaker.Dummy, ?>, ?> createWithDummyValues(MapMaker builder) Returns a freshMapMakerInternalMapwithMapMaker.Dummyvalues but otherwise as specified by the givenbuilder.entrySet()(package private) EReturns the internal entry for the specified key.(package private) VgetLiveValue(E entry) Gets the value from an entry.(package private) intbooleanisEmpty()(package private) booleanisLiveForTesting(MapMakerInternalMap.InternalEntry<K, V, ?> entry) This method is a convenience for testing.keySet()(package private) MapMakerInternalMap.Strength(package private) final MapMakerInternalMap.Segment<K,V, E, S>[] newSegmentArray(int ssize) voidputIfAbsent(K key, V value) private void(package private) voidreclaimKey(E entry) (package private) voidreclaimValue(MapMakerInternalMap.WeakValueReference<K, V, E> valueReference) (package private) static intrehash(int h) Applies a supplemental hash function to a given hash code, which defends against poor quality hash functions.booleanboolean(package private) MapMakerInternalMap.Segment<K, V, E, S> segmentFor(int hash) Returns the segment that should be used for a key with the given hash.intsize()(package private) static <K,V, E extends MapMakerInternalMap.InternalEntry<K, V, E>>
MapMakerInternalMap.WeakValueReference<K, V, E> (package private) Equivalence<Object> values()(package private) MapMakerInternalMap.Strength(package private) ObjectMethods inherited from class java.util.AbstractMap
clone, equals, hashCode, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
-
Field Details
-
MAXIMUM_CAPACITY
static final int MAXIMUM_CAPACITYThe maximum capacity, used if a higher value is implicitly specified by either of the constructors with arguments. MUST be a power of two no greater than1<<30to ensure that entries are indexable using ints.- See Also:
-
MAX_SEGMENTS
static final int MAX_SEGMENTSThe maximum number of segments to allow; used to bound constructor arguments.- See Also:
-
CONTAINS_VALUE_RETRIES
static final int CONTAINS_VALUE_RETRIESNumber of (unsynchronized) retries in the containsValue method.- See Also:
-
DRAIN_THRESHOLD
static final int DRAIN_THRESHOLDNumber of cache access operations that can be buffered per segment before the cache's recency ordering information is updated. This is used to avoid lock contention by recording a memento of reads and delaying a lock acquisition until the threshold is crossed or a mutation occurs.This must be a (2^n)-1 as it is used as a mask.
- See Also:
-
DRAIN_MAX
static final int DRAIN_MAXMaximum number of entries to be drained in a single cleanup run. This applies independently to the cleanup queue and both reference queues.- See Also:
-
segmentMask
final transient int segmentMaskMask value for indexing into segments. The upper bits of a key's hash code are used to choose the segment. -
segmentShift
final transient int segmentShiftShift value for indexing within segments. Helps prevent entries that end up in the same segment from also ending up in the same bucket. -
segments
final transient MapMakerInternalMap.Segment<K,V, segmentsE extends MapMakerInternalMap.InternalEntry<K, V, E>, S extends MapMakerInternalMap.Segment<K, V, E, S>>[] The segments, each of which is a specialized hash table. -
concurrencyLevel
final int concurrencyLevelThe concurrency level. -
keyEquivalence
Strategy for comparing keys. -
entryHelper
final transient MapMakerInternalMap.InternalEntryHelper<K,V, entryHelperE extends MapMakerInternalMap.InternalEntry<K, V, E>, S extends MapMakerInternalMap.Segment<K, V, E, S>> Strategy for handling entries and segments in a type-safe and efficient manner. -
UNSET_WEAK_VALUE_REFERENCE
static final MapMakerInternalMap.WeakValueReference<Object,Object, UNSET_WEAK_VALUE_REFERENCEMapMakerInternalMap.DummyInternalEntry> A singletonMapMakerInternalMap.WeakValueReferenceused to denote an unset value in an entry with weak values. -
keySet
-
values
-
entrySet
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
Method Details
-
create
static <K,V> MapMakerInternalMap<K,V, create? extends MapMakerInternalMap.InternalEntry<K, V, ?>, ?> (MapMaker builder) Returns a freshMapMakerInternalMapas specified by the givenbuilder. -
createWithDummyValues
static <K> MapMakerInternalMap<K,MapMaker.Dummy, createWithDummyValues? extends MapMakerInternalMap.InternalEntry<K, MapMaker.Dummy, ?>, ?> (MapMaker builder) Returns a freshMapMakerInternalMapwithMapMaker.Dummyvalues but otherwise as specified by the givenbuilder. The returnedMapMakerInternalMapwill be optimized to saved memory. SinceMapMaker.Dummyis a singleton, we don't need to store any values at all. Because of this optimization,build.getValueStrength()must beMapMakerInternalMap.Strength.STRONG.This method is intended to only be used by the internal implementation of
Interners, since a map of dummy values is the exact use case there. -
unsetWeakValueReference
static <K,V, MapMakerInternalMap.WeakValueReference<K,E extends MapMakerInternalMap.InternalEntry<K, V, E>> V, unsetWeakValueReference()E> -
rehash
static int rehash(int h) Applies a supplemental hash function to a given hash code, which defends against poor quality hash functions. This is critical when the concurrent hash map uses power-of-two length hash tables, that otherwise encounter collisions for hash codes that do not differ in lower or upper bits.- Parameters:
h- hash code
-
copyEntry
This method is a convenience for testing. Code should callMapMakerInternalMap.Segment.copyEntry(E, E)directly. -
hash
-
reclaimValue
-
reclaimKey
-
isLiveForTesting
This method is a convenience for testing. Code should callMapMakerInternalMap.Segment.getLiveValue(E)instead. -
segmentFor
Returns the segment that should be used for a key with the given hash.- Parameters:
hash- the hash code for the key- Returns:
- the segment
-
createSegment
-
getLiveValue
Gets the value from an entry. Returnsnullif the entry is invalid, partially-collected or computing. -
newSegmentArray
-
keyStrength
MapMakerInternalMap.Strength keyStrength() -
valueStrength
MapMakerInternalMap.Strength valueStrength() -
valueEquivalence
Equivalence<Object> valueEquivalence() -
isEmpty
public boolean isEmpty() -
size
public int size() -
get
-
getEntry
Returns the internal entry for the specified key. The entry may be computing or partially collected. Does not impact recency ordering. -
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classAbstractMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V> - Overrides:
containsValuein classAbstractMap<K,V>
-
put
-
putIfAbsent
- Specified by:
putIfAbsentin interfaceConcurrentMap<K,V> - Specified by:
putIfAbsentin interfaceMap<K,V>
-
putAll
-
remove
-
remove
-
replace
-
replace
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
writeReplace
Object writeReplace() -
readObject
- Throws:
InvalidObjectException
-