Open sandboxFocus

Method SelectManyRecursiveDistinct

SelectManyRecursiveDistinct<T>(T, Func<T, IEnumerable<T>?>, bool)

Selects the closure of a graph by recursively gathering children, starting from a single root item, and returns distinct items using reference equality.

Declaration
public static HashSet<T> SelectManyRecursiveDistinct<T>(this T root, Func<T, IEnumerable<T>?> getChildren, bool includeRoot = true) where T : class
Parameters
Type Name Description
T root

The initial root item.

Func<T, IEnumerable<T>> getChildren

A function that returns the set of all child nodes connected to a given node.

bool includeRoot

A value indicating whether root itself should be included in the result set.

Returns
Type Description
HashSet<T>

A hash set containing the distinct closure of the graph starting from root.

Type Parameters
Name Description
T

The type of items in the graph.

SelectManyRecursiveDistinct<T>(IEnumerable<T>, Func<T, IEnumerable<T>?>, bool)

Selects the closure of a graph by recursively gathering children for each root item, and returns distinct items using reference equality.

Declaration
public static HashSet<T> SelectManyRecursiveDistinct<T>(this IEnumerable<T> roots, Func<T, IEnumerable<T>?> getChildren, bool includeRoots = true) where T : class
Parameters
Type Name Description
IEnumerable<T> roots

The initial collection of root items.

Func<T, IEnumerable<T>> getChildren

A function that returns the set of all child nodes connected to a given node.

bool includeRoots

A value indicating whether the root items themselves should be included in the result set.

Returns
Type Description
HashSet<T>

A hash set containing the distinct closure of the graph starting from roots.

Type Parameters
Name Description
T

The type of items in the graph.

SelectManyRecursiveDistinct<T>(IEnumerable<T>, Func<T, IEnumerable<T>?>, IEqualityComparer<T>, bool)

Selects the closure of a graph by recursively gathering children for each root item, and returns distinct items using a specified equality comparer.

Declaration
public static HashSet<T> SelectManyRecursiveDistinct<T>(this IEnumerable<T> roots, Func<T, IEnumerable<T>?> getChildren, IEqualityComparer<T> equalityComparer, bool includeRoots = true)
Parameters
Type Name Description
IEnumerable<T> roots

The initial collection of root items.

Func<T, IEnumerable<T>> getChildren

A function that returns the set of all child nodes connected to a given node.

IEqualityComparer<T> equalityComparer

The equality comparer to use for determining distinct items.

bool includeRoots

A value indicating whether the root items themselves should be included in the result set.

Returns
Type Description
HashSet<T>

A hash set containing the distinct closure of the graph starting from roots.

Type Parameters
Name Description
T

The type of items in the graph.