Class ConcurrentLongLongHashMap

  • public class ConcurrentLongLongHashMap
    extends java.lang.Object
    Concurrent hash map from primitive long to long.

    Provides similar methods as a ConcurrentMap<K,V> but since it's an open hash map with linear probing, no node allocations are required to store the values.

    Keys MUST be >= 0.
    WARN: method forEach do not guarantee thread safety, nor do the keys, values and asMap method.
    The forEach method is specifically designed for single-threaded usage. When iterating over a map with concurrent writes, it becomes possible for new values to be either observed or not observed. There is no guarantee that if we write value1 and value2, and are able to see value2, then we will also see value1. In some cases, it is even possible to encounter two mappings with the same key, leading the keys method to return a List containing two identical keys.
    It is crucial to understand that the results obtained from aggregate status methods such as keys, values, and asMap are typically reliable only when the map is not undergoing concurrent updates from other threads. When concurrent updates are involved, the results of these methods reflect transient states that may be suitable for monitoring or estimation purposes, but not for program control.

    • Constructor Detail

      • ConcurrentLongLongHashMap

        public ConcurrentLongLongHashMap()
      • ConcurrentLongLongHashMap

        public ConcurrentLongLongHashMap​(int expectedItems)
      • ConcurrentLongLongHashMap

        public ConcurrentLongLongHashMap​(int expectedItems,
                                         int concurrencyLevel)
      • ConcurrentLongLongHashMap

        public ConcurrentLongLongHashMap​(int expectedItems,
                                         int concurrencyLevel,
                                         float mapFillFactor,
                                         float mapIdleFactor,
                                         boolean autoShrink,
                                         float expandFactor,
                                         float shrinkFactor)
    • Method Detail

      • size

        public long size()
      • sizeInBytes

        public long sizeInBytes()
      • capacity

        public long capacity()
      • isEmpty

        public boolean isEmpty()
      • getUsedBucketCount

        long getUsedBucketCount()
      • get

        public long get​(long key)
        key -
        the value or -1 if the key was not present
      • containsKey

        public boolean containsKey​(long key)
      • put

        public long put​(long key,
                        long value)
      • putIfAbsent

        public long putIfAbsent​(long key,
                                long value)
      • addAndGet

        public long addAndGet​(long key,
                              long delta)
        Atomically add the specified delta to a current value identified by the key. If the entry was not in the map, a new entry with default value 0 is added and then the delta is added.
        key - the entry key
        delta - the delta to add
        the new value of the entry
        java.lang.IllegalArgumentException - if the delta was invalid, such as it would have caused the value to be < 0
      • compareAndSet

        public boolean compareAndSet​(long key,
                                     long currentValue,
                                     long newValue)
        Change the value for a specific key only if it matches the current value.
        key -
        currentValue -
        newValue -
      • remove

        public long remove​(long key)
        Remove an existing entry if found.
        key -
        the value associated with the key or -1 if key was not present
      • remove

        public boolean remove​(long key,
                              long value)
      • removeIf

        public int removeIf​(java.util.function.LongPredicate filter)
      • clear

        public void clear()
      • keys

        public java.util.List<java.lang.Long> keys()
        a new list of all keys (makes a copy)
      • values

        public java.util.List<java.lang.Long> values()
      • asMap

        public java.util.Map<java.lang.Long,​java.lang.Long> asMap()
      • hash

        static final long hash​(long key)
      • signSafeMod

        static final int signSafeMod​(long n,
                                     int max)
      • toString

        public java.lang.String toString()
        toString in class java.lang.Object