Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ElementAtQueryOperator.cs
Go to the documentation of this file.
4
6
7internal sealed class ElementAtQueryOperator<TSource> : UnaryQueryOperator<TSource, TSource>
8{
9 private sealed class ElementAtQueryOperatorEnumerator : QueryOperatorEnumerator<TSource, int>
10 {
12
13 private readonly int _index;
14
16
18
26
27 internal override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TSource currentElement, ref int currentKey)
28 {
29 int num = 0;
30 while (_source.MoveNext(ref currentElement, ref currentKey))
31 {
32 if ((num++ & 0x3F) == 0)
33 {
35 }
37 {
38 break;
39 }
40 if (currentKey == _index)
41 {
42 _resultFoundFlag.Value = true;
43 return true;
44 }
45 }
46 return false;
47 }
48
49 protected override void Dispose(bool disposing)
50 {
52 }
53 }
54
55 private readonly int _index;
56
57 private readonly bool _prematureMerge;
58
59 private readonly bool _limitsParallelism;
60
61 internal override bool LimitsParallelism => _limitsParallelism;
62
64 : base(child)
65 {
66 _index = index;
67 OrdinalIndexState ordinalIndexState = base.Child.OrdinalIndexState;
68 if (ordinalIndexState.IsWorseThan(OrdinalIndexState.Correct))
69 {
70 _prematureMerge = true;
72 }
73 }
74
75 internal override QueryResults<TSource> Open(QuerySettings settings, bool preferStriping)
76 {
77 QueryResults<TSource> childQueryResults = base.Child.Open(settings, preferStriping: false);
79 }
80
93
94 [ExcludeFromCodeCoverage(Justification = "This method should never be called as fallback to sequential is handled in Aggregate()")]
96 {
97 throw new NotSupportedException();
98 }
99
100 internal bool Aggregate([MaybeNullWhen(false)] out TSource result, bool withDefaultValue)
101 {
102 if (LimitsParallelism && base.SpecifiedQuerySettings.WithDefaults().ExecutionMode.Value != ParallelExecutionMode.ForceParallelism)
103 {
104 CancellationState cancellationState = base.SpecifiedQuerySettings.CancellationState;
106 {
107 IEnumerable<TSource> source = base.Child.AsSequentialQuery(cancellationState.ExternalCancellationToken);
109 result = ExceptionAggregator.WrapEnumerable(source2, cancellationState).ElementAtOrDefault(_index);
110 }
111 else
112 {
113 IEnumerable<TSource> source3 = base.Child.AsSequentialQuery(cancellationState.ExternalCancellationToken);
115 result = ExceptionAggregator.WrapEnumerable(source4, cancellationState).ElementAt(_index);
116 }
117 return true;
118 }
119 using (IEnumerator<TSource> enumerator = GetEnumerator(ParallelMergeOptions.FullyBuffered))
120 {
121 if (enumerator.MoveNext())
122 {
123 TSource current = enumerator.Current;
124 result = current;
125 return true;
126 }
127 }
128 result = default(TSource);
129 return false;
130 }
131}
override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TSource currentElement, ref int currentKey)
ElementAtQueryOperatorEnumerator(QueryOperatorEnumerator< TSource, int > source, int index, Shared< bool > resultFoundFlag, CancellationToken cancellationToken)
ElementAtQueryOperator(IEnumerable< TSource > child, int index)
override QueryResults< TSource > Open(QuerySettings settings, bool preferStriping)
bool Aggregate([MaybeNullWhen(false)] out TSource result, bool withDefaultValue)
override IEnumerable< TSource > AsSequentialQuery(CancellationToken token)
override void WrapPartitionedStream< TKey >(PartitionedStream< TSource, TKey > inputStream, IPartitionedStreamRecipient< TSource > recipient, bool preferStriping, QuerySettings settings)
bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TElement currentElement, [AllowNull] ref TKey currentKey)