mscorlib(4.0.0.0) API with additions
OrderablePartitioner.cs
3 
5 {
8  [__DynamicallyInvokable]
9  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
10  public abstract class OrderablePartitioner<TSource> : Partitioner<TSource>
11  {
12  private class EnumerableDropIndices : IEnumerable<TSource>, IEnumerable, IDisposable
13  {
14  private readonly IEnumerable<KeyValuePair<long, TSource>> m_source;
15 
16  public EnumerableDropIndices(IEnumerable<KeyValuePair<long, TSource>> source)
17  {
18  m_source = source;
19  }
20 
21  public IEnumerator<TSource> GetEnumerator()
22  {
23  return new EnumeratorDropIndices(m_source.GetEnumerator());
24  }
25 
27  {
28  return GetEnumerator();
29  }
30 
31  public void Dispose()
32  {
33  (m_source as IDisposable)?.Dispose();
34  }
35  }
36 
37  private class EnumeratorDropIndices : IEnumerator<TSource>, IDisposable, IEnumerator
38  {
39  private readonly IEnumerator<KeyValuePair<long, TSource>> m_source;
40 
41  public TSource Current => m_source.Current.Value;
42 
43  object IEnumerator.Current
44  {
45  get
46  {
47  return Current;
48  }
49  }
50 
51  public EnumeratorDropIndices(IEnumerator<KeyValuePair<long, TSource>> source)
52  {
53  m_source = source;
54  }
55 
56  public bool MoveNext()
57  {
58  return m_source.MoveNext();
59  }
60 
61  public void Dispose()
62  {
63  m_source.Dispose();
64  }
65 
66  public void Reset()
67  {
68  m_source.Reset();
69  }
70  }
71 
74  [__DynamicallyInvokable]
75  public bool KeysOrderedInEachPartition
76  {
77  [__DynamicallyInvokable]
78  get;
79  private set;
80  }
81 
84  [__DynamicallyInvokable]
85  public bool KeysOrderedAcrossPartitions
86  {
87  [__DynamicallyInvokable]
88  get;
89  private set;
90  }
91 
94  [__DynamicallyInvokable]
95  public bool KeysNormalized
96  {
97  [__DynamicallyInvokable]
98  get;
99  private set;
100  }
101 
106  [__DynamicallyInvokable]
107  protected OrderablePartitioner(bool keysOrderedInEachPartition, bool keysOrderedAcrossPartitions, bool keysNormalized)
108  {
109  KeysOrderedInEachPartition = keysOrderedInEachPartition;
110  KeysOrderedAcrossPartitions = keysOrderedAcrossPartitions;
111  KeysNormalized = keysNormalized;
112  }
113 
117  [__DynamicallyInvokable]
118  public abstract IList<IEnumerator<KeyValuePair<long, TSource>>> GetOrderablePartitions(int partitionCount);
119 
123  [__DynamicallyInvokable]
125  {
126  throw new NotSupportedException(Environment.GetResourceString("Partitioner_DynamicPartitionsNotSupported"));
127  }
128 
132  [__DynamicallyInvokable]
133  public override IList<IEnumerator<TSource>> GetPartitions(int partitionCount)
134  {
135  IList<IEnumerator<KeyValuePair<long, TSource>>> orderablePartitions = GetOrderablePartitions(partitionCount);
136  if (orderablePartitions.Count != partitionCount)
137  {
138  throw new InvalidOperationException("OrderablePartitioner_GetPartitions_WrongNumberOfPartitions");
139  }
140  IEnumerator<TSource>[] array = new IEnumerator<TSource>[partitionCount];
141  for (int i = 0; i < partitionCount; i++)
142  {
143  array[i] = new EnumeratorDropIndices(orderablePartitions[i]);
144  }
145  return array;
146  }
147 
151  [__DynamicallyInvokable]
153  {
155  return new EnumerableDropIndices(orderableDynamicPartitions);
156  }
157  }
158 }
abstract IList< IEnumerator< KeyValuePair< long, TSource > > > GetOrderablePartitions(int partitionCount)
Partitions the underlying collection into the specified number of orderable partitions.
Represents a non-generic collection of objects that can be individually accessed by index.
Definition: IList.cs:8
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
Definition: IDisposable.cs:8
virtual IEnumerable< KeyValuePair< long, TSource > > GetOrderableDynamicPartitions()
Creates an object that can partition the underlying collection into a variable number of partitions.
Definition: __Canon.cs:3
bool KeysOrderedInEachPartition
Gets whether elements in each partition are yielded in the order of increasing keys.
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Represents a particular manner of splitting an orderable data source into multiple partitions.
bool KeysOrderedAcrossPartitions
Gets whether elements in an earlier partition always come before elements in a later partition.
override IEnumerable< TSource > GetDynamicPartitions()
Creates an object that can partition the underlying collection into a variable number of partitions.
object Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:15
IEnumerator GetEnumerator()
Returns an enumerator that iterates through a collection.
The exception that is thrown when a method call is invalid for the object's current state.
int Count
Gets the number of elements contained in the T:System.Collections.ICollection.
Definition: ICollection.cs:14
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
bool KeysNormalized
Gets whether order keys are normalized.
override IList< IEnumerator< TSource > > GetPartitions(int partitionCount)
Partitions the underlying collection into the given number of ordered partitions.
Represents a particular manner of splitting a data source into multiple partitions.
Definition: Partitioner.cs:12
OrderablePartitioner(bool keysOrderedInEachPartition, bool keysOrderedAcrossPartitions, bool keysNormalized)
Called from constructors in derived classes to initialize the T:System.Collections....