Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TakeOrSkipQueryOperator.cs
Go to the documentation of this file.
4
6
7internal sealed class TakeOrSkipQueryOperator<TResult> : UnaryQueryOperator<TResult, TResult>
8{
9 private sealed class TakeOrSkipQueryOperatorEnumerator<TKey> : QueryOperatorEnumerator<TResult, TKey>
10 {
12
13 private readonly int _count;
14
15 private readonly bool _take;
16
17 private readonly IComparer<TKey> _keyComparer;
18
20
22
24
26
28
39
40 internal override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TResult currentElement, [AllowNull] ref TKey currentKey)
41 {
42 if (_buffer == null && _count > 0)
43 {
46 TKey currentKey2 = default(TKey);
47 int num = 0;
49 {
50 if ((num++ & 0x3F) == 0)
51 {
53 }
56 {
58 {
59 break;
60 }
61 }
62 }
65 _buffer = list;
66 _bufferIndex = new Shared<int>(-1);
67 }
68 if (_take)
69 {
70 if (_count == 0 || _bufferIndex.Value >= _buffer.Count - 1)
71 {
72 return false;
73 }
76 currentKey = _buffer[_bufferIndex.Value].Second;
77 if (_sharedIndices.Count != 0)
78 {
80 }
81 return true;
82 }
83 TKey val = default(TKey);
84 if (_count > 0)
85 {
87 {
88 return false;
89 }
92 {
95 {
96 if (_keyComparer.Compare(_buffer[_bufferIndex.Value].Second, val) > 0)
97 {
99 currentKey = _buffer[_bufferIndex.Value].Second;
100 return true;
101 }
103 }
104 }
105 }
106 if (_source.MoveNext(ref currentElement, ref currentKey))
107 {
108 return true;
109 }
110 return false;
111 }
112
113 protected override void Dispose(bool disposing)
114 {
116 }
117 }
118
120 {
122
123 private readonly int _childCount;
124
125 internal override bool IsIndexible => _childCount >= 0;
126
127 internal override int ElementsCount
128 {
129 get
130 {
131 if (_takeOrSkipOp._take)
132 {
134 }
136 }
137 }
138
147
154
155 internal override TResult GetElement(int index)
156 {
157 if (_takeOrSkipOp._take)
158 {
159 return _childQueryResults.GetElement(index);
160 }
161 return _childQueryResults.GetElement(_takeOrSkipOp._count + index);
162 }
163 }
164
165 private readonly int _count;
166
167 private readonly bool _take;
168
169 private bool _prematureMerge;
170
171 internal override bool LimitsParallelism => false;
172
174 : base(child)
175 {
176 _count = count;
177 _take = take;
179 }
180
182 {
183 OrdinalIndexState ordinalIndexState = base.Child.OrdinalIndexState;
184 if (ordinalIndexState == OrdinalIndexState.Indexable)
185 {
186 return OrdinalIndexState.Indexable;
187 }
188 if (ordinalIndexState.IsWorseThan(OrdinalIndexState.Increasing))
189 {
190 _prematureMerge = true;
192 }
193 if (!_take && ordinalIndexState == OrdinalIndexState.Correct)
194 {
196 }
197 return ordinalIndexState;
198 }
199
201 {
202 if (_prematureMerge)
203 {
204 ListQueryResults<TResult> listQueryResults = QueryOperator<TResult>.ExecuteAndCollectResults(inputStream, inputStream.PartitionCount, base.Child.OutputOrdered, preferStriping, settings);
207 }
208 else
209 {
210 WrapHelper(inputStream, recipient, settings);
211 }
212 }
213
226
227 internal override QueryResults<TResult> Open(QuerySettings settings, bool preferStriping)
228 {
229 QueryResults<TResult> childQueryResults = base.Child.Open(settings, preferStriping: true);
231 }
232
234 {
235 if (_take)
236 {
237 return base.Child.AsSequentialQuery(token).Take(_count);
238 }
239 IEnumerable<TResult> source = CancellableEnumerable.Wrap(base.Child.AsSequentialQuery(token), token);
240 return source.Skip(_count);
241 }
242}
void Add(TKey key, TValue value)
bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TElement currentElement, [AllowNull] ref TKey currentKey)
TakeOrSkipQueryOperatorEnumerator(QueryOperatorEnumerator< TResult, TKey > source, bool take, FixedMaxHeap< TKey > sharedIndices, CountdownEvent sharedBarrier, CancellationToken cancellationToken, IComparer< TKey > keyComparer)
override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TResult currentElement, [AllowNull] ref TKey currentKey)
static QueryResults< TResult > NewResults(QueryResults< TResult > childQueryResults, TakeOrSkipQueryOperator< TResult > op, QuerySettings settings, bool preferStriping)
TakeOrSkipQueryOperatorResults(QueryResults< TResult > childQueryResults, TakeOrSkipQueryOperator< TResult > takeOrSkipOp, QuerySettings settings, bool preferStriping)
override QueryResults< TResult > Open(QuerySettings settings, bool preferStriping)
override void WrapPartitionedStream< TKey >(PartitionedStream< TResult, TKey > inputStream, IPartitionedStreamRecipient< TResult > recipient, bool preferStriping, QuerySettings settings)
TakeOrSkipQueryOperator(IEnumerable< TResult > child, int count, bool take)
override IEnumerable< TResult > AsSequentialQuery(CancellationToken token)
void WrapHelper< TKey >(PartitionedStream< TResult, TKey > inputStream, IPartitionedStreamRecipient< TResult > recipient, QuerySettings settings)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738