Click or drag to resize

IndexPartitionCreateT Method (IEnumerableT)

Creates a partition of positions in a collection of elements by aggregating those positions occupied by a same element.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static IndexPartition<T> Create<T>(
	IEnumerable<T> elements
)
where T : Object, IComparable<T>

Parameters

elements
Type: System.Collections.GenericIEnumerableT
The collection of elements whose positions are to be partitioned.

Type Parameters

T
The type of the elements whose positions are to be partitioned.

Return Value

Type: IndexPartitionT
The partition of element positions in the specified collection.
Exceptions
ExceptionCondition
ArgumentNullExceptionelements is null.
Examples

In the following example, the indexes of an array of strings are partitioned by their contents.

Partitioning the indexes of an array by its contents
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class IndexPartitionExample3  
    {
        public void Main()
        {
            // Create an array of strings.
            var data = new string[6] {
                "one",
                "two",
                "one",
                "one",
                "three",
                "three"
            };

            // Partition the array positions by their contents.
            var partition = IndexPartition.Create(data);

            // The partition contains three parts, identified, respectively,
            // by the strings "one", "two", and "three".
            Console.WriteLine();
            foreach (var identifier in partition.Identifiers) {
                Console.WriteLine("Part identifier: {0}", identifier);
                Console.WriteLine("     indexes: {0}", partition[identifier]);
                Console.WriteLine();
            }
        }
    }
}

// Executing method Main() produces the following output:
// 
// 
// Part identifier: one
//      indexes: 0, 2, 3
// 
// Part identifier: three
//      indexes: 4, 5
// 
// Part identifier: two
//      indexes: 1

See Also