Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TakeOrSkipWhileQueryOperator.cs
Go to the documentation of this file.
4
6
7internal sealed class TakeOrSkipWhileQueryOperator<TResult> : UnaryQueryOperator<TResult, TResult>
8{
9 private sealed class TakeOrSkipWhileQueryOperatorEnumerator<TKey> : QueryOperatorEnumerator<TResult, TKey>
10 {
12
14
16
17 private readonly bool _take;
18
19 private readonly IComparer<TKey> _keyComparer;
20
22
24
26
28
30
31 private int _updatesSeen;
32
33 private TKey _currentLowKey;
34
46
47 internal override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TResult currentElement, [AllowNull] ref TKey currentKey)
48 {
49 if (_buffer == null)
50 {
52 try
53 {
55 TKey currentKey2 = default(TKey);
56 int num = 0;
58 {
59 if ((num++ & 0x3F) == 0)
60 {
62 }
64 if (_updatesSeen != _operatorState._updatesDone)
65 {
67 {
68 _currentLowKey = _operatorState._currentLowKey;
69 _updatesSeen = _operatorState._updatesDone;
70 }
71 }
73 {
74 break;
75 }
77 {
78 continue;
79 }
81 {
82 if (_operatorState._updatesDone == 0 || _keyComparer.Compare(_operatorState._currentLowKey, currentKey2) > 0)
83 {
84 _currentLowKey = (_operatorState._currentLowKey = currentKey2);
85 _updatesSeen = ++_operatorState._updatesDone;
86 }
87 }
88 break;
89 }
90 }
91 finally
92 {
94 }
96 _buffer = list;
97 _bufferIndex = new Shared<int>(-1);
98 }
99 if (_take)
100 {
101 if (_bufferIndex.Value >= _buffer.Count - 1)
102 {
103 return false;
104 }
107 currentKey = _buffer[_bufferIndex.Value].Second;
108 if (_operatorState._updatesDone != 0)
109 {
110 return _keyComparer.Compare(_operatorState._currentLowKey, currentKey) > 0;
111 }
112 return true;
113 }
114 if (_operatorState._updatesDone == 0)
115 {
116 return false;
117 }
119 {
122 {
123 if (_keyComparer.Compare(_buffer[_bufferIndex.Value].Second, _operatorState._currentLowKey) >= 0)
124 {
126 currentKey = _buffer[_bufferIndex.Value].Second;
127 return true;
128 }
130 }
131 }
132 if (_source.MoveNext(ref currentElement, ref currentKey))
133 {
134 return true;
135 }
136 return false;
137 }
138
139 protected override void Dispose(bool disposing)
140 {
142 }
143 }
144
145 private sealed class OperatorState<TKey>
146 {
147 internal volatile int _updatesDone;
148
149 internal TKey _currentLowKey;
150 }
151
153
155
156 private readonly bool _take;
157
158 private bool _prematureMerge;
159
160 private bool _limitsParallelism;
161
162 internal override bool LimitsParallelism => _limitsParallelism;
163
172
173 private void InitOrderIndexState()
174 {
176 OrdinalIndexState ordinalIndexState = base.Child.OrdinalIndexState;
177 if (_indexedPredicate != null)
178 {
179 state = OrdinalIndexState.Correct;
181 }
183 if (ordinalIndexState2.IsWorseThan(state))
184 {
185 _prematureMerge = true;
186 }
187 if (!_take)
188 {
190 }
192 }
193
195 {
196 if (_prematureMerge)
197 {
198 ListQueryResults<TResult> listQueryResults = QueryOperator<TResult>.ExecuteAndCollectResults(inputStream, inputStream.PartitionCount, base.Child.OutputOrdered, preferStriping, settings);
201 }
202 else
203 {
204 WrapHelper(inputStream, recipient, settings);
205 }
206 }
207
221
222 internal override QueryResults<TResult> Open(QuerySettings settings, bool preferStriping)
223 {
224 QueryResults<TResult> childQueryResults = base.Child.Open(settings, preferStriping: true);
226 }
227
229 {
230 if (_take)
231 {
232 if (_indexedPredicate != null)
233 {
234 return base.Child.AsSequentialQuery(token).TakeWhile(_indexedPredicate);
235 }
236 return base.Child.AsSequentialQuery(token).TakeWhile(_predicate);
237 }
238 if (_indexedPredicate != null)
239 {
240 IEnumerable<TResult> source = CancellableEnumerable.Wrap(base.Child.AsSequentialQuery(token), token);
241 return source.SkipWhile(_indexedPredicate);
242 }
243 IEnumerable<TResult> source2 = CancellableEnumerable.Wrap(base.Child.AsSequentialQuery(token), token);
244 return source2.SkipWhile(_predicate);
245 }
246}
void Add(TKey key, TValue value)
bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TElement currentElement, [AllowNull] ref TKey currentKey)
TakeOrSkipWhileQueryOperatorEnumerator(QueryOperatorEnumerator< TResult, TKey > source, Func< TResult, bool > predicate, Func< TResult, TKey, bool > indexedPredicate, bool take, OperatorState< TKey > operatorState, CountdownEvent sharedBarrier, CancellationToken cancelToken, IComparer< TKey > keyComparer)
override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TResult currentElement, [AllowNull] ref TKey currentKey)
override QueryResults< TResult > Open(QuerySettings settings, bool preferStriping)
TakeOrSkipWhileQueryOperator(IEnumerable< TResult > child, Func< TResult, bool > predicate, Func< TResult, int, bool > indexedPredicate, bool take)
override IEnumerable< TResult > AsSequentialQuery(CancellationToken token)
override void WrapPartitionedStream< TKey >(PartitionedStream< TResult, TKey > inputStream, IPartitionedStreamRecipient< TResult > recipient, bool preferStriping, QuerySettings settings)
void WrapHelper< TKey >(PartitionedStream< TResult, TKey > inputStream, IPartitionedStreamRecipient< TResult > recipient, QuerySettings settings)