Table of Contents

Class SetExtensions

Namespace
AlgorithmsSW.Set
Assembly
AlgorithmsSW.dll

Provides extension methods for set operations like union, intersection, difference, and symmetric difference.

public static class SetExtensions
Inheritance
SetExtensions
Inherited Members

Remarks

Many of these methods rely on iterating over the elements of the set, which for many sets are not efficient.

Methods

AddRange<T>(ISet<T>, IEnumerable<T>)

Adds a list of items to a set.

public static void AddRange<T>(this ISet<T> set, IEnumerable<T> items)

Parameters

set ISet<T>

The set to add the items to.

items IEnumerable<T>

The items to add.

Type Parameters

T

The type of the items in the set.

Difference<T>(ISet<T>, ISet<T>)

Produces the difference of two sets.

public static ISet<T> Difference<T>(this ISet<T> set1, ISet<T> set2)

Parameters

set1 ISet<T>

The first set (minuend).

set2 ISet<T>

The second set (subtrahend).

Returns

ISet<T>

A new set containing all elements that are in set1 but not in set2.

Type Parameters

T

Intersection<T>(ISet<T>, IEnumerable<T>)

Produces the intersection of two sets.

public static ISet<T> Intersection<T>(this ISet<T> set1, IEnumerable<T> set2)

Parameters

set1 ISet<T>

The first set.

set2 IEnumerable<T>

The second set.

Returns

ISet<T>

A new set containing all elements that are in both set1 and set2.

Type Parameters

T

SymmetricDifference<T>(ISet<T>, ISet<T>)

Produces the symmetric difference of two sets.

public static ISet<T> SymmetricDifference<T>(this ISet<T> set1, ISet<T> set2)

Parameters

set1 ISet<T>

The first set.

set2 ISet<T>

The second set.

Returns

ISet<T>

A new set containing elements that are in either set1 or set2, but not in both.

Type Parameters

T

Union<T>(ISet<T>, ISet<T>)

Produces the union of two sets.

public static ISet<T> Union<T>(this ISet<T> set1, ISet<T> set2)

Parameters

set1 ISet<T>

The first set.

set2 ISet<T>

The second set.

Returns

ISet<T>

A new set containing all elements that are in either set1 or set2.

Type Parameters

T