DataSharp/Mathematics/SetHelper.cs
/// <summary>
/// Returns a collection that contains all the subsets of the input set with specified number of elements.
/// </summary>
/// <remarks>
/// This method is suitable for the SortedSet&lt;T> class.
/// </remarks>
/// <typeparam name="T">The type of elements in the set.</typeparam>
/// <param name="set">The input set.</param>
/// <param name="numSelection">The number of elements in every subset to be generated.</param>
/// <returns>A collection that contains all the subsets of the input set with specified number of elements.</returns>
Returns a collection that contains all the subsets of the input set with specified number of elements.
Returns a collection that contains all the subsets of the input set with specified number of elements .
public static IEnumerable<SortedSet<T>> GetSubsets<T>(SortedSet<T> set, int numSelection)
        {
            LengthCheck(set.Count, numSelection);
            T[] values = set.ToArray();
            IEnumerable<T[]> combinations = CombinationHelper.Combinations(values, numSelection);
            LinkedList<SortedSet<T>> subsets = new LinkedList<SortedSet<T>>();
            foreach (T[] combination in combinations)
                subsets.AddLast(new SortedSet<T>(combination));
            return subsets;
        }
public static IEnumerable < SortedSet < T > > GetSubsets < T > ( SortedSet < T > set , int numSelection ) { LengthCheck ( set . Count , numSelection ) ; T [ ] values = set . ToArray ( ) ; IEnumerable < T [ ] > combinations = CombinationHelper . Combinations ( values , numSelection ) ; LinkedList < SortedSet < T > > subsets = new LinkedList < SortedSet < T > > ( ) ; foreach ( T [ ] combination in combinations ) subsets . AddLast ( new SortedSet < T > ( combination ) ) ; return subsets ; }
Returns a collection that contains all the subsets of the input set with specified number of elements.
Returns a collection that contains all the subsets of the input set with specified number of elements .
// Check length before processing. // Get the array format of the set. // Get all the subsets in a collection with the array format. // Generate the subsets using the array format we computed above. // Return the collection that contains all the subset of the original set with specified number of elements.
A collection that contains all the subsets of the input set with specified number of elements.
A collection that contains all the subsets of the input set with specified number of elements .
set
SortedSet<T>
The input set.
The input set .
numSelection
int
The number of elements in every subset to be generated.
The number of elements in every subset to be generated .
remarks
This method is suitable for the SortedSet class.
This method is suitable for the SortedSet class .
typeparam
The type of elements in the set.
The type of elements in the set .