Package com.jogamp.common.util
Class WeakIdentityHashMap<K,V>
- java.lang.Object
-
- com.jogamp.common.util.WeakIdentityHashMap<K,V>
-
- All Implemented Interfaces:
Map<K,V>
public class WeakIdentityHashMap<K,V> extends Object implements Map<K,V>
Implements a combination of WeakHashMap and IdentityHashMap. Useful for caches that need to key off of a == comparison instead of a .equals. This class is not a general-purpose Map implementation! While this class implements the Map interface, it intentionally violates Map's general contract, which mandates the use of the equals method when comparing objects. This class is designed for use only in the rare cases wherein reference-equality semantics are required. Note that this implementation is not synchronized.
-
-
Constructor Summary
Constructors Constructor Description WeakIdentityHashMap()
SeeHashMap()
WeakIdentityHashMap(int initialCapacity, float loadFactor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static int
capacityForRequiredSize(int requiredSize, float[] loadFactor)
Returns the [initial] capacity using the givenloadFactor
andrequiredSize
.void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
static WeakIdentityHashMap<?,?>
createWithRequiredSize(int requiredSize, float loadFactor)
Static creation method usingcapacityForRequiredSize(int, float[])
to instantiate a newWeakIdentityHashMap
viaWeakIdentityHashMap(int, float)
.Set<Map.Entry<K,V>>
entrySet()
boolean
equals(Object o)
V
get(Object key)
int
hashCode()
boolean
isEmpty()
Set<K>
keySet()
V
put(K key, V value)
void
putAll(Map<? extends K,? extends V> t)
V
remove(Object key)
int
size()
Collection<V>
values()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
WeakIdentityHashMap
public WeakIdentityHashMap()
SeeHashMap()
-
WeakIdentityHashMap
public WeakIdentityHashMap(int initialCapacity, float loadFactor)
SeeHashMap(int, float)
Usable slots before resize are
capacity * loadFactor
.Capacity for n-slots w/o resize would be
(float)n/loadFactor + 1.0f
, seecapacityForRequiredSize(int, float[])
.- Parameters:
initialCapacity
- default value would be 16, i.e. 12 slots @ 0.75f loadFactor before resizeloadFactor
- default value would be 0.75f- See Also:
capacityForRequiredSize(int, float[])
,createWithRequiredSize(int, float)
-
-
Method Detail
-
createWithRequiredSize
public static WeakIdentityHashMap<?,?> createWithRequiredSize(int requiredSize, float loadFactor)
Static creation method usingcapacityForRequiredSize(int, float[])
to instantiate a newWeakIdentityHashMap
viaWeakIdentityHashMap(int, float)
.- Parameters:
requiredSize
- the user desired n-slots before resizeloadFactor
- given loadFactor, which might be increased a little to avoid next PowerOf2 bloat- Returns:
- the new
WeakIdentityHashMap
instance
-
capacityForRequiredSize
public static int capacityForRequiredSize(int requiredSize, float[] loadFactor)
Returns the [initial] capacity using the givenloadFactor
andrequiredSize
.General calculation is
(float)requiredSize/loadFactor + 1.0f
, usingloadFactor := 0.75f
.In case above computed capacity is
Bitfield.Util.isPowerOf2(int)
, the givenloadFactor
will be increased to avoid next PowerOf2 table size initialization.- Parameters:
requiredSize
- the user desired n-slots before resizeloadFactor
- given loadFactor, which might be increased a little to avoid next PowerOf2 bloat- Returns:
- the [initial] capacity to be used for
WeakIdentityHashMap(int, float)
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<K,V>
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
-