Class PartitionerCollection<T>
- Namespace
- Cuemon.Collections.Generic
- Assembly
- Cuemon.Core.dll
Represents a generic and read-only collection that is iterated in partitions. Implements the PartitionerEnumerable<T> Implements the IReadOnlyCollection<T>
public class PartitionerCollection<T> : PartitionerEnumerable<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
TThe type of elements in the collection.
- Inheritance
-
PartitionerCollection<T>
- Implements
-
IEnumerable<T>
- Inherited Members
Examples
The following example shows how to partition a list of numbers into fixed-size groups using PartitionerCollection. It iterates through each partition and prints partition-level and collection-level metadata.
using System;
using System.Collections.Generic;
using Cuemon.Collections.Generic;
namespace MyApp.Examples
{
public class PartitionerCollectionExample
{
public static void Demonstrate()
{
var numbers = new List<int>();
for (int i = 1; i <= 50; i++) numbers.Add(i);
// Process in partitions of 12 items each
var partitioner = new PartitionerCollection<int>(numbers, partitionSize: 12);
Console.WriteLine($"Total items: {partitioner.Count}");
Console.WriteLine($"Partition size: {partitioner.PartitionSize}");
Console.WriteLine($"Total partitions: {partitioner.PartitionsCount}");
Console.WriteLine($"Items remaining: {partitioner.Remaining}");
Console.WriteLine();
int partitionIndex = 0;
while (partitioner.HasPartitions)
{
partitionIndex++;
Console.Write($"Partition {partitionIndex}: ");
foreach (var item in partitioner)
{
Console.Write($"{item} ");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine($"Iterated count: {partitioner.IteratedCount}");
Console.WriteLine($"Has remaining partitions: {partitioner.HasPartitions}");
}}}}
}
Constructors
PartitionerCollection(ICollection<T>, int)
Initializes a new instance of the PartitionerCollection<T> class.
public PartitionerCollection(ICollection<T> source, int partitionSize = 128)
Parameters
sourceICollection<T>The sequence to iterate in partitions.
partitionSizeintThe size of the partitions.
Properties
Count
Gets the total number of elements in the sequence before partitioning is applied.
public int Count { get; }
Property Value
- int
The total number of elements in the sequence before partitioning is applied.
PartitionsCount
Gets the total amount of partitions for the elements in this sequence.
public int PartitionsCount { get; }
Property Value
- int
The total amount of partitions for the elements in this sequence.
Remaining
Gets the number of elements remaining in the partitioned sequence.
public int Remaining { get; }
Property Value
- int
The number of elements remaining in the partitioned sequence.