Class 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.
    • Method Detail

      • capacityForRequiredSize

        public static int capacityForRequiredSize​(int requiredSize,
                                                  float[] loadFactor)
        Returns the [initial] capacity using the given loadFactor and requiredSize.

        General calculation is (float)requiredSize/loadFactor + 1.0f, using loadFactor := 0.75f.

        In case above computed capacity is Bitfield.Util.isPowerOf2(int), the given loadFactor will be increased to avoid next PowerOf2 table size initialization.

        Parameters:
        requiredSize - the user desired n-slots before resize
        loadFactor - given loadFactor, which might be increased a little to avoid next PowerOf2 bloat
        Returns:
        the [initial] capacity to be used for WeakIdentityHashMap(int, float)
      • clear

        public void clear()
        Specified by:
        clear in interface Map<K,​V>
      • containsKey

        public boolean containsKey​(Object key)
        Specified by:
        containsKey in interface Map<K,​V>
      • keySet

        public Set<K> keySet()
        Specified by:
        keySet in interface Map<K,​V>
      • get

        public V get​(Object key)
        Specified by:
        get in interface Map<K,​V>
      • put

        public V put​(K key,
                     V value)
        Specified by:
        put in interface Map<K,​V>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface Map<K,​V>
      • putAll

        public void putAll​(Map<? extends K,​? extends V> t)
        Specified by:
        putAll in interface Map<K,​V>
      • remove

        public V remove​(Object key)
        Specified by:
        remove in interface Map<K,​V>
      • size

        public int size()
        Specified by:
        size in interface Map<K,​V>