Class ConcurrentSet<T>
- Namespace
- Garyon.DataStructures
- Assembly
- Garyon.dll
Provides a thread-safe set implementation based on ConcurrentDictionary<TKey, TValue>.
public sealed class ConcurrentSet<T> : ISet<T>, ICollection<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable where T : notnull
Type Parameters
TThe type of values stored in the set.
- Inheritance
-
ConcurrentSet<T>
- Implements
-
ISet<T>ICollection<T>IEnumerable<T>
- Inherited Members
- Extension Methods
Remarks
This encapsulates ConcurrentDictionary<TKey, TValue> as a
concurrent set, using byte as the value type that is mapped
from the key of T. The idea of using byte is inspired
by dotnet/roslyn.
Constructors
ConcurrentSet()
Initializes a new instance of the ConcurrentSet<T> class.
public ConcurrentSet()
ConcurrentSet(IEqualityComparer<T>)
Initializes a new instance of the ConcurrentSet<T> class with the specified equality comparer.
public ConcurrentSet(IEqualityComparer<T> comparer)
Parameters
comparerIEqualityComparer<T>
Properties
Count
Gets the number of elements contained in the set.
public int Count { get; }
Property Value
IsEmpty
Gets a value indicating whether the set is empty.
public bool IsEmpty { get; }
Property Value
Methods
Add(T)
Adds the specified value to the set.
public bool Add(T value)
Parameters
valueT
Returns
Clear()
Removes all elements from the set.
public void Clear()
Contains(T)
Determines whether the ICollection<T> contains a specific value.
public bool Contains(T item)
Parameters
itemTThe object to locate in the ICollection<T>.
Returns
- bool
true if
itemis found in the ICollection<T>; otherwise, false.
ExceptWith(IEnumerable<T>)
Removes all elements in the specified collection from the current set.
public void ExceptWith(IEnumerable<T> other)
Parameters
otherIEnumerable<T>The collection of items to remove from the set.
Exceptions
- ArgumentNullException
otheris null.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
An enumerator that can be used to iterate through the collection.
IntersectWith(IEnumerable<T>)
Modifies the current set so that it contains only elements that are also in a specified collection.
public void IntersectWith(IEnumerable<T> other)
Parameters
otherIEnumerable<T>The collection to compare to the current set.
Exceptions
- ArgumentNullException
otheris null.
IsProperSubsetOf(IEnumerable<T>)
Determines whether the current set is a proper (strict) subset of a specified collection.
public bool IsProperSubsetOf(IEnumerable<T> other)
Parameters
otherIEnumerable<T>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
otheris null.
IsProperSupersetOf(IEnumerable<T>)
Determines whether the current set is a proper (strict) superset of a specified collection.
public bool IsProperSupersetOf(IEnumerable<T> other)
Parameters
otherIEnumerable<T>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
otheris null.
IsSubsetOf(IEnumerable<T>)
Determines whether a set is a subset of a specified collection.
public bool IsSubsetOf(IEnumerable<T> other)
Parameters
otherIEnumerable<T>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
otheris null.
IsSupersetOf(IEnumerable<T>)
Determines whether the current set is a superset of a specified collection.
public bool IsSupersetOf(IEnumerable<T> other)
Parameters
otherIEnumerable<T>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
otheris null.
Overlaps(IEnumerable<T>)
Determines whether the current set overlaps with the specified collection.
public bool Overlaps(IEnumerable<T> other)
Parameters
otherIEnumerable<T>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
otheris null.
Remove(T)
Removes the first occurrence of a specific object from the ICollection<T>.
public bool Remove(T item)
Parameters
itemTThe object to remove from the ICollection<T>.
Returns
- bool
true if
itemwas successfully removed from the ICollection<T>; otherwise, false. This method also returns false ifitemis not found in the original ICollection<T>.
Exceptions
- NotSupportedException
The ICollection<T> is read-only.
SetEquals(IEnumerable<T>)
Determines whether the current set and the specified collection contain the same elements.
public bool SetEquals(IEnumerable<T> other)
Parameters
otherIEnumerable<T>The collection to compare to the current set.
Returns
Exceptions
- ArgumentNullException
otheris null.
SymmetricExceptWith(IEnumerable<T>)
Modifies the current set so that it contains only elements that are present either in the current set or in the specified collection, but not both.
public void SymmetricExceptWith(IEnumerable<T> other)
Parameters
otherIEnumerable<T>The collection to compare to the current set.
Exceptions
- ArgumentNullException
otheris null.
TryRemove(T)
Tries to remove the value from the set.
public bool TryRemove(T value)
Parameters
valueT
Returns
UnionWith(IEnumerable<T>)
Modifies the current set so that it contains all elements that are present in the current set, in the specified collection, or in both.
public void UnionWith(IEnumerable<T> other)
Parameters
otherIEnumerable<T>The collection to compare to the current set.
Exceptions
- ArgumentNullException
otheris null.