Class ConcurrentHashSet<T>
Represents a thread-safe hash-based unique collection.
Inherited Members
Namespace: Mapsui.Utilities
Assembly: Mapsui.dll
Syntax
public class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
| Name | Description |
|---|---|
| T | The type of the items in the collection. |
Remarks
All public members of ConcurrentHashSet<T> are thread-safe and may be used concurrently from multiple threads.
Constructors
| Edit this page View SourceConcurrentHashSet()
Initializes a new instance of the ConcurrentHashSet<T> class that is empty, has the default concurrency level, has the default initial capacity, and uses the default comparer for the item type.
Declaration
public ConcurrentHashSet()
ConcurrentHashSet(IEnumerable<T>)
Initializes a new instance of the ConcurrentHashSet<T> class that contains elements copied from the specified IEnumerable, has the default concurrency level, has the default initial capacity, and uses the default comparer for the item type.
Declaration
public ConcurrentHashSet(IEnumerable<T> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | The IEnumerable whose elements are copied to the new ConcurrentHashSet<T>. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
ConcurrentHashSet(IEnumerable<T>, IEqualityComparer<T>?)
Initializes a new instance of the ConcurrentHashSet<T> class that contains elements copied from the specified IEnumerable, has the default concurrency level, has the default initial capacity, and uses the specified System.Collections.Generic.IEqualityComparer{T}.
Declaration
public ConcurrentHashSet(IEnumerable<T> collection, IEqualityComparer<T>? comparer)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | The IEnumerable whose elements are copied to the new ConcurrentHashSet<T>. |
| IEqualityComparer<T> | comparer | The System.Collections.Generic.IEqualityComparer{T} implementation to use when comparing items. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
ConcurrentHashSet(IEqualityComparer<T>?)
Initializes a new instance of the ConcurrentHashSet<T> class that is empty, has the specified concurrency level and capacity, and uses the specified System.Collections.Generic.IEqualityComparer{T}.
Declaration
public ConcurrentHashSet(IEqualityComparer<T>? comparer)
Parameters
| Type | Name | Description |
|---|---|---|
| IEqualityComparer<T> | comparer | The System.Collections.Generic.IEqualityComparer{T} implementation to use when comparing items. |
ConcurrentHashSet(int, IEnumerable<T>, IEqualityComparer<T>)
Initializes a new instance of the ConcurrentHashSet<T> class that contains elements copied from the specified IEnumerable, has the specified concurrency level, has the specified initial capacity, and uses the specified System.Collections.Generic.IEqualityComparer{T}.
Declaration
public ConcurrentHashSet(int concurrencyLevel, IEnumerable<T> collection, IEqualityComparer<T> comparer)
Parameters
| Type | Name | Description |
|---|---|---|
| int | concurrencyLevel | The estimated number of threads that will update the ConcurrentHashSet<T> concurrently. |
| IEnumerable<T> | collection | The IEnumerable whose elements are copied to the new ConcurrentHashSet<T>. |
| IEqualityComparer<T> | comparer | The System.Collections.Generic.IEqualityComparer{T} implementation to use when comparing items. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
|
ConcurrentHashSet(int, int)
Initializes a new instance of the ConcurrentHashSet<T> class that is empty, has the specified concurrency level and capacity, and uses the default comparer for the item type.
Declaration
public ConcurrentHashSet(int concurrencyLevel, int capacity)
Parameters
| Type | Name | Description |
|---|---|---|
| int | concurrencyLevel | The estimated number of threads that will update the ConcurrentHashSet<T> concurrently. |
| int | capacity | The initial number of elements that the ConcurrentHashSet<T> can contain. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
| ArgumentOutOfRangeException |
|
ConcurrentHashSet(int, int, IEqualityComparer<T>)
Initializes a new instance of the ConcurrentHashSet<T> class that is empty, has the specified concurrency level, has the specified initial capacity, and uses the specified System.Collections.Generic.IEqualityComparer{T}.
Declaration
public ConcurrentHashSet(int concurrencyLevel, int capacity, IEqualityComparer<T> comparer)
Parameters
| Type | Name | Description |
|---|---|---|
| int | concurrencyLevel | The estimated number of threads that will update the ConcurrentHashSet<T> concurrently. |
| int | capacity | The initial number of elements that the ConcurrentHashSet<T> can contain. |
| IEqualityComparer<T> | comparer | The System.Collections.Generic.IEqualityComparer{T} implementation to use when comparing items. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
Properties
| Edit this page View SourceCount
Gets the number of items contained in the ConcurrentHashSet<T>.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int | The number of items contained in the ConcurrentHashSet<T>. |
Remarks
Count has snapshot semantics and represents the number of items in the ConcurrentHashSet<T> at the moment when Count was accessed.
IsEmpty
Gets a value that indicates whether the ConcurrentHashSet<T> is empty.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool | true if the ConcurrentHashSet<T> is empty; otherwise, false. |
Methods
| Edit this page View SourceAdd(T)
Adds the specified item to the ConcurrentHashSet<T>.
Declaration
public bool Add(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to add. |
Returns
| Type | Description |
|---|---|
| bool | true if the items was added to the ConcurrentHashSet<T> successfully; false if it already exists. |
Exceptions
| Type | Condition |
|---|---|
| OverflowException | The ConcurrentHashSet<T> contains too many items. |
Clear()
Removes all items from the ConcurrentHashSet<T>.
Declaration
public void Clear()
Contains(T)
Determines whether the ConcurrentHashSet<T> contains the specified item.
Declaration
public bool Contains(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to locate in the ConcurrentHashSet<T>. |
Returns
| Type | Description |
|---|---|
| bool | true if the ConcurrentHashSet<T> contains the item; otherwise, false. |
GetEnumerator()
Returns an enumerator that iterates through the ConcurrentHashSet<T>.
Declaration
public IEnumerator<T> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<T> | An enumerator for the ConcurrentHashSet<T>. |
Remarks
The enumerator returned from the collection is safe to use concurrently with reads and writes to the collection, however it does not represent a moment-in-time snapshot of the collection. The contents exposed through the enumerator may contain modifications made to the collection after GetEnumerator() was called.
TryRemove(T)
Attempts to remove the item from the ConcurrentHashSet<T>.
Declaration
public bool TryRemove(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to remove. |
Returns
| Type | Description |
|---|---|
| bool | true if an item was removed successfully; otherwise, false. |