6 internal sealed
class AnyAllSearchOperator<TInput> : UnaryQueryOperator<TInput, bool>
8 private class AnyAllSearchOperatorEnumerator<TKey> : QueryOperatorEnumerator<bool, int>
10 private readonly QueryOperatorEnumerator<TInput, TKey> m_source;
12 private readonly Func<TInput, bool> m_predicate;
14 private readonly
bool m_qualification;
16 private readonly
int m_partitionIndex;
18 private readonly Shared<bool> m_resultFoundFlag;
22 internal AnyAllSearchOperatorEnumerator(QueryOperatorEnumerator<TInput, TKey> source,
bool qualification, Func<TInput, bool> predicate,
int partitionIndex, Shared<bool> resultFoundFlag,
CancellationToken cancellationToken)
25 m_qualification = qualification;
26 m_predicate = predicate;
27 m_partitionIndex = partitionIndex;
28 m_resultFoundFlag = resultFoundFlag;
29 m_cancellationToken = cancellationToken;
32 internal override bool MoveNext(ref
bool currentElement, ref
int currentKey)
34 if (m_resultFoundFlag.Value)
38 TInput currentElement2 =
default(TInput);
39 TKey currentKey2 =
default(TKey);
40 if (m_source.MoveNext(ref currentElement2, ref currentKey2))
42 currentElement = !m_qualification;
43 currentKey = m_partitionIndex;
47 if ((num++ & 0x3F) == 0)
49 CancellationState.ThrowIfCanceled(m_cancellationToken);
51 if (m_resultFoundFlag.Value)
55 if (m_predicate(currentElement2) == m_qualification)
57 m_resultFoundFlag.Value =
true;
58 currentElement = m_qualification;
62 while (m_source.MoveNext(ref currentElement2, ref currentKey2));
68 protected override void Dispose(
bool disposing)
74 private readonly Func<TInput, bool> m_predicate;
76 private readonly
bool m_qualification;
78 internal override bool LimitsParallelism =>
false;
80 internal AnyAllSearchOperator(
IEnumerable<TInput> child,
bool qualification, Func<TInput, bool> predicate)
83 m_qualification = qualification;
84 m_predicate = predicate;
87 internal bool Aggregate()
93 if (enumerator.
Current == m_qualification)
95 return m_qualification;
99 return !m_qualification;
102 internal override QueryResults<bool> Open(QuerySettings settings,
bool preferStriping)
104 QueryResults<TInput> childQueryResults = base.Child.Open(settings, preferStriping);
105 return new UnaryQueryOperatorResults(childQueryResults,
this, settings, preferStriping);
108 internal override void WrapPartitionedStream<TKey>(PartitionedStream<TInput, TKey> inputStream, IPartitionedStreamRecipient<bool> recipient,
bool preferStriping, QuerySettings settings)
110 Shared<bool> resultFoundFlag =
new Shared<bool>(value:
false);
111 int partitionCount = inputStream.PartitionCount;
112 PartitionedStream<bool, int> partitionedStream =
new PartitionedStream<bool, int>(partitionCount, Util.GetDefaultComparer<
int>(), OrdinalIndexState.Correct);
113 for (
int i = 0; i < partitionCount; i++)
115 partitionedStream[i] =
new AnyAllSearchOperatorEnumerator<TKey>(inputStream[i], m_qualification, m_predicate, i, resultFoundFlag, settings.CancellationState.MergedCancellationToken);
117 recipient.Receive(partitionedStream);
Propagates notification that operations should be canceled.
bool MoveNext()
Advances the enumerator to the next element of the collection.
Exposes the enumerator, which supports a simple iteration over a collection of a specified type....
Supports a simple iteration over a generic collection.
ParallelMergeOptions
Specifies the preferred type of output merge to use in a query. In other words, it indicates how PLIN...
new T Current
Gets the element in the collection at the current position of the enumerator.
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...