Package alluxio.collections
Class ConcurrentIdentityHashMap<K,V>
- java.lang.Object
-
- alluxio.collections.ConcurrentIdentityHashMap<K,V>
-
- Type Parameters:
K
- the type of keys maintained by this mapV
- the type of mapped values
- All Implemented Interfaces:
java.util.concurrent.ConcurrentMap<K,V>
,java.util.Map<K,V>
@ThreadSafe public class ConcurrentIdentityHashMap<K,V> extends java.lang.Object implements java.util.concurrent.ConcurrentMap<K,V>
An implementationConcurrentHashMap
that utilizes identity semantics with its keys Having identity semantics means that it is possible to have two objects with which are equal based on the object'sequals()
implementation, but not be overridden in the hash map if you try to put both. For example:ConcurrentIdentityHashMap<String, Boolean> map = new ConcurrentIdentityHashMap<>(); String s1 = new String("test"); String s2 = new String("test"); map.put(s1, true); map.put(s2, false); map.size(); // Prints "2". map.get(s1); // true map.get(s2); // false
Keys in this mapped are hashed based on the identity, that is, the location in memory of the objects rather than the equality which java typically uses for comparison. This implementation ofConcurrentMap
has a few limitations which the correspondingConcurrentHashMap
does not have. - This map'sentrySet()
returns a copy of the entries at the time of calling the method. The returned set does will not receive updates from the underlying map. This is a departure from the behavior ofConcurrentHashMap
- This map'skeySet()
does return the map-backed keySet and provides the same behavior as inConcurrentHashMap
, however the difference is thatSet.toArray()
andSet.toArray(Object[])
methods are left unimplemented and will throw an error if the user attempts to convert the set into an array.
-
-
Constructor Summary
Constructors Constructor Description ConcurrentIdentityHashMap()
Creates a new, empty map with the default initial table size (16).ConcurrentIdentityHashMap(int initialCapacity)
Creates a new, empty map with an initial table size accommodating the specified number of elements without having to dynamically resize.ConcurrentIdentityHashMap(int initialCapacity, float loadFactor)
Creates a new, empty map with an initial table size based on the given number of elements (initialCapacity
) and initial load factor (loadFactor
) with aconcurrencyLevel
of 1.ConcurrentIdentityHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)
Creates a new, empty map with an initial table size based on the given number of elements (initialCapacity
), load factor (loadFactor
), and number of expected concurrently updating threads (concurrencyLevel
).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(java.lang.Object k)
boolean
containsValue(java.lang.Object value)
java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
Returns a set representing the entries of this map at the time of calling.V
get(java.lang.Object k)
boolean
isEmpty()
java.util.Set<K>
keySet()
Returns a set representing all keys contained within the map.V
put(K k, V v)
void
putAll(java.util.Map<? extends K,? extends V> map)
V
putIfAbsent(K k, V v)
V
remove(java.lang.Object k)
boolean
remove(java.lang.Object k, java.lang.Object v)
V
replace(K k, V v)
boolean
replace(K k, V v1, V v2)
int
size()
java.util.Collection<V>
values()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
ConcurrentIdentityHashMap
public ConcurrentIdentityHashMap()
Creates a new, empty map with the default initial table size (16).
-
ConcurrentIdentityHashMap
public ConcurrentIdentityHashMap(int initialCapacity)
Creates a new, empty map with an initial table size accommodating the specified number of elements without having to dynamically resize.- Parameters:
initialCapacity
- The implementation performs internal sizing to accommodate this many elements.- Throws:
java.lang.IllegalArgumentException
- if the initial capacity of elements is negative
-
ConcurrentIdentityHashMap
public ConcurrentIdentityHashMap(int initialCapacity, float loadFactor)
Creates a new, empty map with an initial table size based on the given number of elements (initialCapacity
) and initial load factor (loadFactor
) with aconcurrencyLevel
of 1.- Parameters:
initialCapacity
- the initial capacity. The implementation performs internal sizing to accommodate this many elements, given the specified load factor.loadFactor
- the load factor (table density) for establishing the initial table size- Throws:
java.lang.IllegalArgumentException
- if the initial capacity of elements is negative or the load factor is nonpositive
-
ConcurrentIdentityHashMap
public ConcurrentIdentityHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)
Creates a new, empty map with an initial table size based on the given number of elements (initialCapacity
), load factor (loadFactor
), and number of expected concurrently updating threads (concurrencyLevel
).- Parameters:
initialCapacity
- the initial capacity. The implementation performs internal sizing to accommodate this many elements, given the specified load factor.loadFactor
- the load factor (table density) for establishing the initial table sizeconcurrencyLevel
- the estimated number of concurrently updating threads. The implementation may use this value as a sizing hint.- Throws:
java.lang.IllegalArgumentException
- if the initial capacity is negative or the load factor or concurrencyLevel are nonpositive
-
-
Method Detail
-
containsKey
public boolean containsKey(java.lang.Object k)
-
remove
public boolean remove(java.lang.Object k, java.lang.Object v)
-
values
public java.util.Collection<V> values()
-
entrySet
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Returns a set representing the entries of this map at the time of calling. Note, this method will create a copy of the map's entry set at creation time. Standard behavior in theConcurrentHashMap
says that the entry set backed by the map is updated when the underlying map is updated. That is not the case for this class.
-
containsValue
public boolean containsValue(java.lang.Object value)
-
keySet
public java.util.Set<K> keySet()
Returns a set representing all keys contained within the map. Note this method departs slightly from the standardConcurrentHashMap
implementation by providing its own implementation of a Set forConcurrentIdentityHashMap.IdentityObject
. Not all methods have been implemented. Namely thetoArray
,add*
, and*all(Collection<?> c)
methods.
-
-