Class ConcurrentOpenHashSet<V>
- java.lang.Object
-
- org.apache.bookkeeper.util.collections.ConcurrentOpenHashSet<V>
-
- Type Parameters:
V
-
public class ConcurrentOpenHashSet<V> extends java.lang.Object
Concurrent hash set.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
WARN: method forEach do not guarantee thread safety, nor does the values 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 values 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConcurrentOpenHashSet.Builder<V>
Builder of ConcurrentOpenHashSet.
-
Constructor Summary
Constructors Constructor Description ConcurrentOpenHashSet()
Deprecated.ConcurrentOpenHashSet(int expectedItems)
Deprecated.ConcurrentOpenHashSet(int expectedItems, int concurrencyLevel)
Deprecated.ConcurrentOpenHashSet(int expectedItems, int concurrencyLevel, float mapFillFactor, float mapIdleFactor, boolean autoShrink, float expandFactor, float shrinkFactor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(V value)
long
capacity()
void
clear()
boolean
contains(V value)
void
forEach(java.util.function.Consumer<? super V> processor)
Iterate over all the elements in the set and apply the provided function.(package private) long
getUsedBucketCount()
(package private) static <K> long
hash(K key)
boolean
isEmpty()
static <V> ConcurrentOpenHashSet.Builder<V>
newBuilder()
boolean
remove(V value)
(package private) static int
signSafeMod(long n, int max)
long
size()
(package private) java.util.List<V>
values()
-
-
-
Constructor Detail
-
ConcurrentOpenHashSet
@Deprecated public ConcurrentOpenHashSet()
Deprecated.
-
ConcurrentOpenHashSet
@Deprecated public ConcurrentOpenHashSet(int expectedItems)
Deprecated.
-
ConcurrentOpenHashSet
@Deprecated public ConcurrentOpenHashSet(int expectedItems, int concurrencyLevel)
Deprecated.
-
ConcurrentOpenHashSet
public ConcurrentOpenHashSet(int expectedItems, int concurrencyLevel, float mapFillFactor, float mapIdleFactor, boolean autoShrink, float expandFactor, float shrinkFactor)
-
-
Method Detail
-
newBuilder
public static <V> ConcurrentOpenHashSet.Builder<V> newBuilder()
-
size
public long size()
-
capacity
public long capacity()
-
getUsedBucketCount
long getUsedBucketCount()
-
isEmpty
public boolean isEmpty()
-
contains
public boolean contains(V value)
-
add
public boolean add(V value)
-
remove
public boolean remove(V value)
-
clear
public void clear()
-
forEach
public void forEach(java.util.function.Consumer<? super V> processor)
Iterate over all the elements in the set and apply the provided function.Warning: Do Not Guarantee Thread-Safety.
- Parameters:
processor
- the function to apply to each element
-
values
java.util.List<V> values()
- Returns:
- a new list of all values (makes a copy)
-
hash
static final <K> long hash(K key)
-
signSafeMod
static final int signSafeMod(long n, int max)
-
-