Class ConcurrentLongPairSet

java.lang.Object
org.apache.pulsar.common.util.collections.ConcurrentLongPairSet
All Implemented Interfaces:
LongPairSet

public class ConcurrentLongPairSet extends Object implements LongPairSet
Concurrent hash set where values are composed of pairs of longs.

Provides similar methods as a ConcurrentHashSet<V> but since it's an open hash set with linear probing, no node allocations are required to store the keys and values, and no boxing is required.

Values MUST be >= 0.
WARN: method forEach do not guarantee thread safety, nor does the items method.
The forEach method is specifically designed for single-threaded usage. When iterating over a set 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.
It is crucial to understand that the results obtained from aggregate status methods such as items 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

    • ConcurrentLongPairSet

      @Deprecated public ConcurrentLongPairSet()
      Deprecated.
    • ConcurrentLongPairSet

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

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

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

    • newBuilder

      public static ConcurrentLongPairSet.Builder newBuilder()
    • size

      public long size()
      Description copied from interface: LongPairSet
      Returns size of the set.
      Specified by:
      size in interface LongPairSet
      Returns:
    • capacity

      public long capacity()
      Description copied from interface: LongPairSet
      Returns capacity of the set.
      Specified by:
      capacity in interface LongPairSet
      Returns:
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: LongPairSet
      Check if set is empty.
      Specified by:
      isEmpty in interface LongPairSet
      Returns:
    • contains

      public boolean contains(long item1, long item2)
      Description copied from interface: LongPairSet
      Checks if given (item1,item2) composite value exists into set.
      Specified by:
      contains in interface LongPairSet
      Returns:
    • add

      public boolean add(long item1, long item2)
      Description copied from interface: LongPairSet
      Adds composite value of item1 and item2 to set.
      Specified by:
      add in interface LongPairSet
      Returns:
    • remove

      public boolean remove(long item1, long item2)
      Remove an existing entry if found.
      Specified by:
      remove in interface LongPairSet
      Parameters:
      item1 -
      Returns:
      true if removed or false if item was not present
    • clear

      public void clear()
      Description copied from interface: LongPairSet
      Removes all items from set.
      Specified by:
      clear in interface LongPairSet
    • forEach

      public void forEach(ConcurrentLongPairSet.LongPairConsumer processor)
      Iterate over all the elements in the set and apply the provided function.

      Warning: Do Not Guarantee Thread-Safety.

      Specified by:
      forEach in interface LongPairSet
      Parameters:
      processor - the processor to process the elements
    • removeIf

      public int removeIf(LongPairSet.LongPairPredicate filter)
      Removes all of the elements of this collection that satisfy the given predicate.
      Specified by:
      removeIf in interface LongPairSet
      Parameters:
      filter - a predicate which returns true for elements to be removed
      Returns:
      number of removed values
    • items

      Specified by:
      items in interface LongPairSet
      Returns:
      a new set of all keys (makes a copy)
    • items

      public Set<ConcurrentLongPairSet.LongPair> items(int numberOfItems)
      Specified by:
      items in interface LongPairSet
      Returns:
      a new list of keys with max provided numberOfItems (makes a copy)
    • items

      public <T> Set<T> items(int numberOfItems, LongPairSet.LongPairFunction<T> longPairConverter)
      Specified by:
      items in interface LongPairSet
      longPairConverter - converts (long,long) pair to object
      Returns:
      a new list of keys with max provided numberOfItems
    • toString

      public String toString()
      Overrides:
      toString in class Object