Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LastQueryOperator.cs
Go to the documentation of this file.
4
6
7internal sealed class LastQueryOperator<TSource> : UnaryQueryOperator<TSource, TSource>
8{
9 private sealed class LastQueryOperatorEnumerator<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 bool flag = false;
47 try
48 {
49 int num = 0;
50 TSource currentElement2 = default(TSource);
51 TKey currentKey2 = default(TKey);
53 {
54 if ((num & 0x3F) == 0)
55 {
57 }
59 {
60 val = currentElement2;
62 flag = true;
63 }
64 num++;
65 }
66 if (flag)
67 {
69 {
70 if (_operatorState._partitionId == -1 || _keyComparer.Compare(val2, _operatorState._key) > 0)
71 {
72 _operatorState._partitionId = _partitionId;
73 _operatorState._key = val2;
74 }
75 }
76 }
77 }
78 finally
79 {
81 }
82 _alreadySearched = true;
83 if (_partitionId == _operatorState._partitionId)
84 {
86 if (_operatorState._partitionId == _partitionId)
87 {
88 currentElement = val;
89 currentKey = 0;
90 return true;
91 }
92 }
93 return false;
94 }
95
96 protected override void Dispose(bool disposing)
97 {
99 }
100 }
101
102 private sealed class LastQueryOperatorState<TKey>
103 {
104 internal TKey _key;
105
106 internal int _partitionId = -1;
107 }
108
110
111 private readonly bool _prematureMergeNeeded;
112
113 internal override bool LimitsParallelism => false;
114
116 : base(child)
117 {
119 _prematureMergeNeeded = base.Child.OrdinalIndexState.IsWorseThan(OrdinalIndexState.Increasing);
120 }
121
122 internal override QueryResults<TSource> Open(QuerySettings settings, bool preferStriping)
123 {
124 QueryResults<TSource> childQueryResults = base.Child.Open(settings, preferStriping: false);
126 }
127
129 {
131 {
132 PartitionedStream<TSource, int> partitionedStream = QueryOperator<TSource>.ExecuteAndCollectResults(inputStream, inputStream.PartitionCount, base.Child.OutputOrdered, preferStriping, settings).GetPartitionedStream();
134 }
135 else
136 {
137 WrapHelper(inputStream, recipient, settings);
138 }
139 }
140
153
154 [ExcludeFromCodeCoverage(Justification = "This method should never be called as fallback to sequential is handled in ParallelEnumerable.First()")]
156 {
157 throw new NotSupportedException();
158 }
159}
readonly QueryOperatorEnumerator< TSource, TKey > _source
override bool MoveNext([MaybeNullWhen(false)][AllowNull] ref TSource currentElement, ref int currentKey)
LastQueryOperatorEnumerator(QueryOperatorEnumerator< TSource, TKey > source, Func< TSource, bool > predicate, LastQueryOperatorState< TKey > operatorState, CountdownEvent sharedBarrier, CancellationToken cancelToken, IComparer< TKey > keyComparer, int partitionId)
LastQueryOperator(IEnumerable< TSource > child, Func< TSource, bool > predicate)
override IEnumerable< TSource > AsSequentialQuery(CancellationToken token)
override void WrapPartitionedStream< TKey >(PartitionedStream< TSource, TKey > inputStream, IPartitionedStreamRecipient< TSource > recipient, bool preferStriping, QuerySettings settings)
override QueryResults< TSource > Open(QuerySettings settings, bool preferStriping)
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)