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 intcapacityForRequiredSize(int requiredSize, float[] loadFactor)Returns the [initial] capacity using the givenloadFactorandrequiredSize.voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)static WeakIdentityHashMap<?,?>createWithRequiredSize(int requiredSize, float loadFactor)Static creation method usingcapacityForRequiredSize(int, float[])to instantiate a newWeakIdentityHashMapviaWeakIdentityHashMap(int, float).Set<Map.Entry<K,V>>entrySet()booleanequals(Object o)Vget(Object key)inthashCode()booleanisEmpty()Set<K>keySet()Vput(K key, V value)voidputAll(Map<? extends K,? extends V> t)Vremove(Object key)intsize()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 newWeakIdentityHashMapviaWeakIdentityHashMap(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
WeakIdentityHashMapinstance
-
capacityForRequiredSize
public static int capacityForRequiredSize(int requiredSize, float[] loadFactor)Returns the [initial] capacity using the givenloadFactorandrequiredSize.General calculation is
(float)requiredSize/loadFactor + 1.0f, usingloadFactor := 0.75f.In case above computed capacity is
Bitfield.Util.isPowerOf2(int), the givenloadFactorwill 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:
containsKeyin interfaceMap<K,V>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<K,V>
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
-