mscorlib(4.0.0.0) API with additions
AnyAllSearchOperator.cs
2 using System.Threading;
3 
5 {
6  internal sealed class AnyAllSearchOperator<TInput> : UnaryQueryOperator<TInput, bool>
7  {
8  private class AnyAllSearchOperatorEnumerator<TKey> : QueryOperatorEnumerator<bool, int>
9  {
10  private readonly QueryOperatorEnumerator<TInput, TKey> m_source;
11 
12  private readonly Func<TInput, bool> m_predicate;
13 
14  private readonly bool m_qualification;
15 
16  private readonly int m_partitionIndex;
17 
18  private readonly Shared<bool> m_resultFoundFlag;
19 
20  private readonly CancellationToken m_cancellationToken;
21 
22  internal AnyAllSearchOperatorEnumerator(QueryOperatorEnumerator<TInput, TKey> source, bool qualification, Func<TInput, bool> predicate, int partitionIndex, Shared<bool> resultFoundFlag, CancellationToken cancellationToken)
23  {
24  m_source = source;
25  m_qualification = qualification;
26  m_predicate = predicate;
27  m_partitionIndex = partitionIndex;
28  m_resultFoundFlag = resultFoundFlag;
29  m_cancellationToken = cancellationToken;
30  }
31 
32  internal override bool MoveNext(ref bool currentElement, ref int currentKey)
33  {
34  if (m_resultFoundFlag.Value)
35  {
36  return false;
37  }
38  TInput currentElement2 = default(TInput);
39  TKey currentKey2 = default(TKey);
40  if (m_source.MoveNext(ref currentElement2, ref currentKey2))
41  {
42  currentElement = !m_qualification;
43  currentKey = m_partitionIndex;
44  int num = 0;
45  do
46  {
47  if ((num++ & 0x3F) == 0)
48  {
49  CancellationState.ThrowIfCanceled(m_cancellationToken);
50  }
51  if (m_resultFoundFlag.Value)
52  {
53  return false;
54  }
55  if (m_predicate(currentElement2) == m_qualification)
56  {
57  m_resultFoundFlag.Value = true;
58  currentElement = m_qualification;
59  break;
60  }
61  }
62  while (m_source.MoveNext(ref currentElement2, ref currentKey2));
63  return true;
64  }
65  return false;
66  }
67 
68  protected override void Dispose(bool disposing)
69  {
70  m_source.Dispose();
71  }
72  }
73 
74  private readonly Func<TInput, bool> m_predicate;
75 
76  private readonly bool m_qualification;
77 
78  internal override bool LimitsParallelism => false;
79 
80  internal AnyAllSearchOperator(IEnumerable<TInput> child, bool qualification, Func<TInput, bool> predicate)
81  : base(child)
82  {
83  m_qualification = qualification;
84  m_predicate = predicate;
85  }
86 
87  internal bool Aggregate()
88  {
89  using (IEnumerator<bool> enumerator = GetEnumerator(ParallelMergeOptions.FullyBuffered, suppressOrderPreservation: true))
90  {
91  while (enumerator.MoveNext())
92  {
93  if (enumerator.Current == m_qualification)
94  {
95  return m_qualification;
96  }
97  }
98  }
99  return !m_qualification;
100  }
101 
102  internal override QueryResults<bool> Open(QuerySettings settings, bool preferStriping)
103  {
104  QueryResults<TInput> childQueryResults = base.Child.Open(settings, preferStriping);
105  return new UnaryQueryOperatorResults(childQueryResults, this, settings, preferStriping);
106  }
107 
108  internal override void WrapPartitionedStream<TKey>(PartitionedStream<TInput, TKey> inputStream, IPartitionedStreamRecipient<bool> recipient, bool preferStriping, QuerySettings settings)
109  {
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++)
114  {
115  partitionedStream[i] = new AnyAllSearchOperatorEnumerator<TKey>(inputStream[i], m_qualification, m_predicate, i, resultFoundFlag, settings.CancellationState.MergedCancellationToken);
116  }
117  recipient.Receive(partitionedStream);
118  }
119 
120  internal override IEnumerable<bool> AsSequentialQuery(CancellationToken token)
121  {
122  throw new NotSupportedException();
123  }
124  }
125 }
Propagates notification that operations should be canceled.
bool MoveNext()
Advances the enumerator to the next element of the collection.
Definition: __Canon.cs:3
Exposes the enumerator, which supports a simple iteration over a collection of a specified type....
Definition: IEnumerable.cs:9
Supports a simple iteration over a generic collection.
Definition: IEnumerator.cs:6
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.
Definition: IEnumerator.cs:12
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...