Class UnlockedReadHashMap<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type
    All Implemented Interfaces:
    java.util.concurrent.ConcurrentMap<K,​V>, java.util.Map<K,​V>

    final class UnlockedReadHashMap<K,​V>
    extends java.util.AbstractMap<K,​V>
    implements java.util.concurrent.ConcurrentMap<K,​V>
    A hash map that supports non-blocking, lockless read access.
    • Field Detail

      • DEFAULT_INITIAL_CAPACITY

        private static final int DEFAULT_INITIAL_CAPACITY
        See Also:
        Constant Field Values
      • writeLock

        private final java.lang.Object writeLock
      • entrySet

        private final java.util.Set<java.util.Map.Entry<K,​V>> entrySet
      • loadFactor

        private final float loadFactor
      • size

        private volatile int size
      • threshold

        private int threshold
    • Constructor Detail

      • UnlockedReadHashMap

        public UnlockedReadHashMap​(int initialCapacity,
                                   float loadFactor)
      • UnlockedReadHashMap

        public UnlockedReadHashMap​(float loadFactor)
      • UnlockedReadHashMap

        public UnlockedReadHashMap​(int initialCapacity)
      • UnlockedReadHashMap

        public UnlockedReadHashMap()
    • Method Detail

      • resize

        private void resize()
      • getIndex

        private static <K,​V> int getIndex​(java.util.concurrent.atomic.AtomicReferenceArray<UnlockedReadHashMap.Item<K,​V>[]> table,
                                                java.lang.Object key)
      • doPut

        private V doPut​(java.util.concurrent.atomic.AtomicReferenceArray<UnlockedReadHashMap.Item<K,​V>[]> table,
                        K key,
                        V value,
                        boolean ifAbsent)
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Specified by:
        entrySet in class java.util.AbstractMap<K,​V>
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K,​V>
        Overrides:
        size in class java.util.AbstractMap<K,​V>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K,​V>
        Overrides:
        containsKey in class java.util.AbstractMap<K,​V>
      • get

        public V get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
        Overrides:
        get in class java.util.AbstractMap<K,​V>
      • put

        public V put​(K key,
                     V value)
        Specified by:
        put in interface java.util.Map<K,​V>
        Overrides:
        put in class java.util.AbstractMap<K,​V>
      • remove

        public V remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<K,​V>
        Overrides:
        remove in class java.util.AbstractMap<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<K,​V>
        Overrides:
        clear in class java.util.AbstractMap<K,​V>
      • putIfAbsent

        public V putIfAbsent​(K key,
                             V value)
        Specified by:
        putIfAbsent in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        putIfAbsent in interface java.util.Map<K,​V>
      • remove

        public boolean remove​(java.lang.Object key,
                              java.lang.Object value)
        Specified by:
        remove in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        remove in interface java.util.Map<K,​V>
      • replace

        public boolean replace​(K key,
                               V oldValue,
                               V newValue)
        Specified by:
        replace in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        replace in interface java.util.Map<K,​V>
      • replace

        public V replace​(K key,
                         V value)
        Specified by:
        replace in interface java.util.concurrent.ConcurrentMap<K,​V>
        Specified by:
        replace in interface java.util.Map<K,​V>