Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SelectManyQueryOperator.cs
Go to the documentation of this file.
4
6
7internal sealed class SelectManyQueryOperator<TLeftInput, TRightInput, TOutput> : UnaryQueryOperator<TLeftInput, TOutput>
8{
9 private sealed class IndexedSelectManyQueryOperatorEnumerator : QueryOperatorEnumerator<TOutput, Pair<int, int>>
10 {
11 private sealed class Mutables
12 {
13 internal int _currentRightSourceIndex = -1;
14
15 internal TLeftInput _currentLeftElement;
16
18
19 internal int _lhsCount;
20 }
21
23
25
27
29
31
33
40
41 internal override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TOutput currentElement, ref Pair<int, int> currentKey)
42 {
43 while (true)
44 {
45 if (_currentRightSource == null)
46 {
47 _mutables = new Mutables();
48 if ((_mutables._lhsCount++ & 0x3F) == 0)
49 {
51 }
53 {
54 return false;
55 }
57 _currentRightSource = enumerable.GetEnumerator();
58 if (_selectManyOperator._resultSelector == null)
59 {
61 }
62 }
63 if (_currentRightSource.MoveNext())
64 {
65 break;
66 }
67 _currentRightSource.Dispose();
70 }
72 if (_selectManyOperator._resultSelector != null)
73 {
75 }
76 else
77 {
79 }
81 return true;
82 }
83
84 protected override void Dispose(bool disposing)
85 {
87 if (_currentRightSource != null)
88 {
89 _currentRightSource.Dispose();
90 }
91 }
92 }
93
94 private sealed class SelectManyQueryOperatorEnumerator<TLeftKey> : QueryOperatorEnumerator<TOutput, Pair<TLeftKey, int>>
95 {
96 private sealed class Mutables
97 {
98 internal int _currentRightSourceIndex = -1;
99
100 internal TLeftInput _currentLeftElement;
101
102 internal TLeftKey _currentLeftKey;
103
104 internal int _lhsCount;
105 }
106
108
110
112
114
116
118
125
126 internal override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TOutput currentElement, ref Pair<TLeftKey, int> currentKey)
127 {
128 while (true)
129 {
130 if (_currentRightSource == null)
131 {
132 _mutables = new Mutables();
133 if ((_mutables._lhsCount++ & 0x3F) == 0)
134 {
136 }
138 {
139 return false;
140 }
142 _currentRightSource = enumerable.GetEnumerator();
143 if (_selectManyOperator._resultSelector == null)
144 {
146 }
147 }
148 if (_currentRightSource.MoveNext())
149 {
150 break;
151 }
152 _currentRightSource.Dispose();
153 _currentRightSource = null;
155 }
157 if (_selectManyOperator._resultSelector != null)
158 {
160 }
161 else
162 {
164 }
166 return true;
167 }
168
169 protected override void Dispose(bool disposing)
170 {
172 if (_currentRightSource != null)
173 {
174 _currentRightSource.Dispose();
175 }
176 }
177 }
178
180
182
184
185 private bool _prematureMerge;
186
187 private bool _limitsParallelism;
188
189 internal override bool LimitsParallelism => _limitsParallelism;
190
200
201 private void InitOrderIndex()
202 {
203 OrdinalIndexState ordinalIndexState = base.Child.OrdinalIndexState;
204 if (_indexedRightChildSelector != null)
205 {
208 }
209 else if (base.OutputOrdered)
210 {
211 _prematureMerge = ordinalIndexState.IsWorseThan(OrdinalIndexState.Increasing);
212 }
214 }
215
217 {
218 int partitionCount = inputStream.PartitionCount;
219 if (_indexedRightChildSelector != null)
220 {
222 if (_prematureMerge)
223 {
224 ListQueryResults<TLeftInput> listQueryResults = QueryOperator<TLeftInput>.ExecuteAndCollectResults(inputStream, partitionCount, base.OutputOrdered, preferStriping, settings);
225 inputStream2 = listQueryResults.GetPartitionedStream();
226 }
227 else
228 {
230 }
232 }
233 else if (_prematureMerge)
234 {
235 PartitionedStream<TLeftInput, int> partitionedStream = QueryOperator<TLeftInput>.ExecuteAndCollectResults(inputStream, partitionCount, base.OutputOrdered, preferStriping, settings).GetPartitionedStream();
237 }
238 else
239 {
240 WrapPartitionedStreamNotIndexed(inputStream, recipient, settings);
241 }
242 }
243
255
257 {
258 PairComparer<int, int> keyComparer = new PairComparer<int, int>(inputStream.KeyComparer, Util.GetDefaultComparer<int>());
260 for (int i = 0; i < inputStream.PartitionCount; i++)
261 {
263 }
265 }
266
267 internal override QueryResults<TOutput> Open(QuerySettings settings, bool preferStriping)
268 {
271 }
272
274 {
275 if (_rightChildSelector != null)
276 {
277 if (_resultSelector != null)
278 {
279 return CancellableEnumerable.Wrap(base.Child.AsSequentialQuery(token), token).SelectMany(_rightChildSelector, _resultSelector);
280 }
281 return (IEnumerable<TOutput>)CancellableEnumerable.Wrap(base.Child.AsSequentialQuery(token), token).SelectMany(_rightChildSelector);
282 }
283 if (_resultSelector != null)
284 {
285 return CancellableEnumerable.Wrap(base.Child.AsSequentialQuery(token), token).SelectMany(_indexedRightChildSelector, _resultSelector);
286 }
287 return (IEnumerable<TOutput>)CancellableEnumerable.Wrap(base.Child.AsSequentialQuery(token), token).SelectMany(_indexedRightChildSelector);
288 }
289}
bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TElement currentElement, [AllowNull] ref TKey currentKey)
IndexedSelectManyQueryOperatorEnumerator(QueryOperatorEnumerator< TLeftInput, int > leftSource, SelectManyQueryOperator< TLeftInput, TRightInput, TOutput > selectManyOperator, CancellationToken cancellationToken)
override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TOutput currentElement, ref Pair< int, int > currentKey)
readonly SelectManyQueryOperator< TLeftInput, TRightInput, TOutput > _selectManyOperator
SelectManyQueryOperatorEnumerator(QueryOperatorEnumerator< TLeftInput, TLeftKey > leftSource, SelectManyQueryOperator< TLeftInput, TRightInput, TOutput > selectManyOperator, CancellationToken cancellationToken)
override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TOutput currentElement, ref Pair< TLeftKey, int > currentKey)
readonly SelectManyQueryOperator< TLeftInput, TRightInput, TOutput > _selectManyOperator
SelectManyQueryOperator(IEnumerable< TLeftInput > leftChild, Func< TLeftInput, IEnumerable< TRightInput > > rightChildSelector, Func< TLeftInput, int, IEnumerable< TRightInput > > indexedRightChildSelector, Func< TLeftInput, TRightInput, TOutput > resultSelector)
override QueryResults< TOutput > Open(QuerySettings settings, bool preferStriping)
void WrapPartitionedStreamIndexed(PartitionedStream< TLeftInput, int > inputStream, IPartitionedStreamRecipient< TOutput > recipient, QuerySettings settings)
override void WrapPartitionedStream< TLeftKey >(PartitionedStream< TLeftInput, TLeftKey > inputStream, IPartitionedStreamRecipient< TOutput > recipient, bool preferStriping, QuerySettings settings)
override IEnumerable< TOutput > AsSequentialQuery(CancellationToken token)
void WrapPartitionedStreamNotIndexed< TLeftKey >(PartitionedStream< TLeftInput, TLeftKey > inputStream, IPartitionedStreamRecipient< TOutput > recipient, QuerySettings settings)
readonly Func< TLeftInput, int, IEnumerable< TRightInput > > _indexedRightChildSelector
readonly Func< TLeftInput, TRightInput, TOutput > _resultSelector
readonly Func< TLeftInput, IEnumerable< TRightInput > > _rightChildSelector