Class ConcurrentLongLongHashMap

java.lang.Object
org.apache.bookkeeper.util.collections.ConcurrentLongLongHashMap

public class ConcurrentLongLongHashMap extends 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 Details

    • ConcurrentLongLongHashMap

      @Deprecated public ConcurrentLongLongHashMap()
      Deprecated.
    • ConcurrentLongLongHashMap

      @Deprecated public ConcurrentLongLongHashMap(int expectedItems)
      Deprecated.
    • ConcurrentLongLongHashMap

      @Deprecated public ConcurrentLongLongHashMap(int expectedItems, int concurrencyLevel)
      Deprecated.
    • ConcurrentLongLongHashMap

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

    • newBuilder

      public static ConcurrentLongLongHashMap.Builder newBuilder()
    • 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)
      Parameters:
      key -
      Returns:
      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)
    • computeIfAbsent

      public long computeIfAbsent(long key, ConcurrentLongLongHashMap.LongLongFunction provider)
    • 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.
      Parameters:
      key - the entry key
      delta - the delta to add
      Returns:
      the new value of the entry
      Throws:
      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.
      Parameters:
      key -
      currentValue -
      newValue -
      Returns:
    • remove

      public long remove(long key)
      Remove an existing entry if found.
      Parameters:
      key -
      Returns:
      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(LongPredicate filter)
    • removeIf

      public int removeIf(ConcurrentLongLongHashMap.LongLongPredicate filter)
    • clear

      public void clear()
    • forEach

      public void forEach(ConcurrentLongLongHashMap.BiConsumerLong processor)
    • keys

      public List<Long> keys()
      Returns:
      a new list of all keys (makes a copy)
    • values

      public List<Long> values()
    • asMap

      public Map<Long,Long> asMap()
    • hash

      static final long hash(long key)
    • signSafeMod

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

      public String toString()
      Overrides:
      toString in class Object