Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FirstQueryOperator.cs
Go to the documentation of this file.
4
6
7internal sealed class FirstQueryOperator<TSource> : UnaryQueryOperator<TSource, TSource>
8{
9 private sealed class FirstQueryOperatorEnumerator<TKey> : QueryOperatorEnumerator<TSource, int>
10 {
12
14
15 private bool _alreadySearched;
16
17 private readonly int _partitionId;
18
20
22
24
25 private readonly IComparer<TKey> _keyComparer;
26
37
38 internal override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TSource currentElement, ref int currentKey)
39 {
41 {
42 return false;
43 }
44 TSource val = default(TSource);
45 TKey val2 = default(TKey);
46 try
47 {
48 TSource currentElement2 = default(TSource);
49 TKey currentKey2 = default(TKey);
50 int num = 0;
52 {
53 if ((num++ & 0x3F) == 0)
54 {
56 }
57 if (_predicate != null && !_predicate(currentElement2))
58 {
59 continue;
60 }
61 val = currentElement2;
64 {
65 if (_operatorState._partitionId == -1 || _keyComparer.Compare(val2, _operatorState._key) < 0)
66 {
67 _operatorState._key = val2;
68 _operatorState._partitionId = _partitionId;
69 }
70 }
71 break;
72 }
73 }
74 finally
75 {
77 }
78 _alreadySearched = true;
79 if (_partitionId == _operatorState._partitionId)
80 {
82 if (_partitionId == _operatorState._partitionId)
83 {
84 currentElement = val;
85 currentKey = 0;
86 return true;
87 }
88 }
89 return false;
90 }
91
92 protected override void Dispose(bool disposing)
93 {
95 }
96 }
97
98 private sealed class FirstQueryOperatorState<TKey>
99 {
100 internal TKey _key;
101
102 internal int _partitionId = -1;
103 }
104
106
107 private readonly bool _prematureMergeNeeded;
108
109 internal override bool LimitsParallelism => false;
110
112 : base(child)
113 {
115 _prematureMergeNeeded = base.Child.OrdinalIndexState.IsWorseThan(OrdinalIndexState.Increasing);
116 }
117
118 internal override QueryResults<TSource> Open(QuerySettings settings, bool preferStriping)
119 {
120 QueryResults<TSource> childQueryResults = base.Child.Open(settings, preferStriping: false);
122 }
123
125 {
127 {
128 ListQueryResults<TSource> listQueryResults = QueryOperator<TSource>.ExecuteAndCollectResults(inputStream, inputStream.PartitionCount, base.Child.OutputOrdered, preferStriping, settings);
129 WrapHelper(listQueryResults.GetPartitionedStream(), recipient, settings);
130 }
131 else
132 {
133 WrapHelper(inputStream, recipient, settings);
134 }
135 }
136
149
150 [ExcludeFromCodeCoverage(Justification = "This method should never be called as fallback to sequential is handled in ParallelEnumerable.First()")]
152 {
153 throw new NotSupportedException();
154 }
155}
FirstQueryOperatorEnumerator(QueryOperatorEnumerator< TSource, TKey > source, Func< TSource, bool > predicate, FirstQueryOperatorState< TKey > operatorState, CountdownEvent sharedBarrier, CancellationToken cancellationToken, IComparer< TKey > keyComparer, int partitionId)
override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TSource currentElement, ref int currentKey)
readonly QueryOperatorEnumerator< TSource, TKey > _source
override QueryResults< TSource > Open(QuerySettings settings, bool preferStriping)
override IEnumerable< TSource > AsSequentialQuery(CancellationToken token)
override void WrapPartitionedStream< TKey >(PartitionedStream< TSource, TKey > inputStream, IPartitionedStreamRecipient< TSource > recipient, bool preferStriping, QuerySettings settings)
FirstQueryOperator(IEnumerable< TSource > child, Func< TSource, bool > predicate)
readonly Func< TSource, bool > _predicate
void WrapHelper< TKey >(PartitionedStream< TSource, TKey > inputStream, IPartitionedStreamRecipient< TSource > recipient, QuerySettings settings)
bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TElement currentElement, [AllowNull] ref TKey currentKey)