Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AssociativeAggregationOperator.cs
Go to the documentation of this file.
4
6
7internal sealed class AssociativeAggregationOperator<TInput, TIntermediate, TOutput> : UnaryQueryOperator<TInput, TIntermediate>
8{
9 private sealed class AssociativeAggregationOperatorEnumerator<TKey> : QueryOperatorEnumerator<TIntermediate, int>
10 {
12
14
15 private readonly int _partitionIndex;
16
18
19 private bool _accumulated;
20
28
29 internal override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TIntermediate currentElement, ref int currentKey)
30 {
31 if (_accumulated)
32 {
33 return false;
34 }
35 _accumulated = true;
36 bool flag = false;
37 TIntermediate val = default(TIntermediate);
38 if (_reduceOperator._seedIsSpecified)
39 {
40 val = ((_reduceOperator._seedFactory == null) ? _reduceOperator._seed : _reduceOperator._seedFactory());
41 }
42 else
43 {
44 TInput currentElement2 = default(TInput);
45 TKey currentKey2 = default(TKey);
47 {
48 return false;
49 }
50 flag = true;
51 val = (TIntermediate)(object)currentElement2;
52 }
53 TInput currentElement3 = default(TInput);
54 TKey currentKey3 = default(TKey);
55 int num = 0;
57 {
58 if ((num++ & 0x3F) == 0)
59 {
61 }
62 flag = true;
63 val = _reduceOperator._intermediateReduce(val, currentElement3);
64 }
65 if (flag)
66 {
67 currentElement = val;
68 currentKey = _partitionIndex;
69 return true;
70 }
71 return false;
72 }
73
74 protected override void Dispose(bool disposing)
75 {
77 }
78 }
79
80 private readonly TIntermediate _seed;
81
82 private readonly bool _seedIsSpecified;
83
84 private readonly bool _throwIfEmpty;
85
87
89
91
93
94 internal override bool LimitsParallelism => false;
95
107
108 internal TOutput Aggregate()
109 {
110 TIntermediate val = default(TIntermediate);
111 bool flag = false;
112 using (IEnumerator<TIntermediate> enumerator = GetEnumerator(ParallelMergeOptions.FullyBuffered, suppressOrderPreservation: true))
113 {
114 while (enumerator.MoveNext())
115 {
116 if (flag)
117 {
118 try
119 {
120 val = _finalReduce(val, enumerator.Current);
121 }
122 catch (Exception ex)
123 {
124 throw new AggregateException(ex);
125 }
126 }
127 else
128 {
129 val = enumerator.Current;
130 flag = true;
131 }
132 }
133 if (!flag)
134 {
135 if (_throwIfEmpty)
136 {
138 }
139 val = ((_seedFactory == null) ? _seed : _seedFactory());
140 }
141 }
142 try
143 {
144 return _resultSelector(val);
145 }
146 catch (Exception ex2)
147 {
148 throw new AggregateException(ex2);
149 }
150 }
151
153 {
156 }
157
168
169 [ExcludeFromCodeCoverage(Justification = "This method should never be called. Associative aggregation can always be parallelized")]
171 {
172 throw new NotSupportedException();
173 }
174}
readonly AssociativeAggregationOperator< TInput, TIntermediate, TOutput > _reduceOperator
AssociativeAggregationOperatorEnumerator(QueryOperatorEnumerator< TInput, TKey > source, AssociativeAggregationOperator< TInput, TIntermediate, TOutput > reduceOperator, int partitionIndex, CancellationToken cancellationToken)
override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TIntermediate currentElement, ref int currentKey)
AssociativeAggregationOperator(IEnumerable< TInput > child, TIntermediate seed, Func< TIntermediate > seedFactory, bool seedIsSpecified, Func< TIntermediate, TInput, TIntermediate > intermediateReduce, Func< TIntermediate, TIntermediate, TIntermediate > finalReduce, Func< TIntermediate, TOutput > resultSelector, bool throwIfEmpty, QueryAggregationOptions options)
override IEnumerable< TIntermediate > AsSequentialQuery(CancellationToken token)
readonly Func< TIntermediate, TIntermediate, TIntermediate > _finalReduce
override void WrapPartitionedStream< TKey >(PartitionedStream< TInput, TKey > inputStream, IPartitionedStreamRecipient< TIntermediate > recipient, bool preferStriping, QuerySettings settings)
readonly Func< TIntermediate, TInput, TIntermediate > _intermediateReduce
override QueryResults< TIntermediate > Open(QuerySettings settings, bool preferStriping)
bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TElement currentElement, [AllowNull] ref TKey currentKey)
static string NoElements
Definition SR.cs:16
Definition SR.cs:7