Table of Contents

Class SafeHashSet<T>

Namespace
CMS.Base
Assembly
CMS.Base.dll

Thread-safe variant of a generic hash set

public class SafeHashSet<T>

Type Parameters

T
Inheritance
object
SafeHashSet<T>
Extension Methods

Remarks

Even for reference types, null is not supported value in the safe hash set.

Constructors

SafeHashSet(IEnumerable<T>, IEqualityComparer<T>)

Constructor

public SafeHashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer = null)

Parameters

collection IEnumerable<T>

Source collection

comparer IEqualityComparer<T>

Equality comparer

SafeHashSet(IEqualityComparer<T>)

Constructor

public SafeHashSet(IEqualityComparer<T> comparer = null)

Parameters

comparer IEqualityComparer<T>

Equality comparer

Properties

Count

Returns the number of elements in a sequence.

public int Count { get; }

Property Value

int

IsReadOnly

Gets a value indicating whether a collection is read-only.

public bool IsReadOnly { get; }

Property Value

bool

Methods

Add(T)

Adds the item to the hash set

public bool Add(T item)

Parameters

item T

Value to add

Returns

bool

true if item added, false otherwise

Exceptions

ArgumentNullException

If item is null.

Clear()

Removes all elements from a SafeHashSet<T> object.

public void Clear()

Contains(T)

Returns true if the hash set contains the given value

public bool Contains(T item)

Parameters

item T

Value to check

Returns

bool

Exceptions

ArgumentNullException

If item is null.

CopyTo(T[], int)

Copies the elements of a SafeHashSet<T> object to an array, starting at the specified array index.

public void CopyTo(T[] array, int arrayIndex)

Parameters

array T[]

The one-dimensional array that is the destination of the elements copied from the SafeHashSet<T> object. The array must have zero-based indexing.

arrayIndex int

The zero-based index in array at which copying begins.

Exceptions

ArgumentNullException

If array is null.

ArgumentOutOfRangeException

If arrayIndex is less than the lower bound of array.

ArgumentException

If the number of elements in set is greater than the available number of elements from arrayIndex to the end of the destination array.

ExceptWith(IEnumerable<T>)

Removes all elements in the specified collection from the current SafeHashSet<T> object.

public void ExceptWith(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection of items to remove from the SafeHashSet<T> object.

Exceptions

ArgumentNullException

If other is null.

GetEnumerator()

Returns an enumerator that iterates through a collection.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

IntersectWith(IEnumerable<T>)

Modifies the current SafeHashSet<T> object to contain only elements that are present in that object and in the specified collection.

public void IntersectWith(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current SafeHashSet<T> object.

Exceptions

ArgumentNullException

If other is null.

IsProperSubsetOf(IEnumerable<T>)

Determines whether a SafeHashSet<T> object is a proper subset of the specified collection.

public bool IsProperSubsetOf(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current SafeHashSet<T> object.

Returns

bool

Exceptions

ArgumentNullException

If other is null.

IsProperSupersetOf(IEnumerable<T>)

Determines whether a SafeHashSet<T> object is a proper superset of the specified collection.

public bool IsProperSupersetOf(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current SafeHashSet<T> object.

Returns

bool

Exceptions

ArgumentNullException

If other is null.

IsSubsetOf(IEnumerable<T>)

Determines whether a SafeHashSet<T> object is a subset of the specified collection.

public bool IsSubsetOf(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current SafeHashSet<T> object.

Returns

bool

Exceptions

ArgumentNullException

If other is null.

IsSupersetOf(IEnumerable<T>)

Determines whether a SafeHashSet<T> object is a superset of the specified collection.

public bool IsSupersetOf(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current SafeHashSet<T> object.

Returns

bool

Exceptions

ArgumentNullException

If other is null.

Overlaps(IEnumerable<T>)

Determines whether the current SafeHashSet<T> object and a specified collection share common elements.

public bool Overlaps(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current SafeHashSet<T> object.

Returns

bool

Exceptions

ArgumentNullException

If other is null.

Remove(T)

Removes the value from the hash set

public bool Remove(T item)

Parameters

item T

Value to remove

Returns

bool

Exceptions

ArgumentNullException

If item is null.

SetEquals(IEnumerable<T>)

Determines whether a SafeHashSet<T> object and the specified collection contain the same elements.

public bool SetEquals(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current SafeHashSet<T> object.

Returns

bool

Exceptions

ArgumentNullException

If other is null.

SymmetricExceptWith(IEnumerable<T>)

Modifies the current SafeHashSet<T> object to contain only elements that are present either in that object or in the specified collection, but not both.

public void SymmetricExceptWith(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to compare to the current SafeHashSet<T> object.

Exceptions

ArgumentNullException

If other is null.

UnionWith(IEnumerable<T>)

Modifies the current SafeHashSet<T> object to contain all elements that are present in itself, the specified collection, or both.

public void UnionWith(IEnumerable<T> other)

Parameters

other IEnumerable<T>

The collection to merge into the current SafeHashSet<T> object.

Exceptions

ArgumentNullException

If other is null.