private void WrapHelper <TKey>(PartitionedStream <TResult, TKey> inputStream, IPartitionedStreamRecipient <TResult> recipient, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; if (ParallelEnumerable.SinglePartitionMode) { Debug.Assert(partitionCount == 1); } // Create shared data. OperatorState <TKey> operatorState = new OperatorState <TKey>(); CountdownEvent sharedBarrier = new CountdownEvent(partitionCount); Debug.Assert(_indexedPredicate == null || typeof(TKey) == typeof(int)); Func <TResult, TKey, bool>?convertedIndexedPredicate = (Func <TResult, TKey, bool>?)(object?) _indexedPredicate; PartitionedStream <TResult, TKey> partitionedStream = new PartitionedStream <TResult, TKey>(partitionCount, inputStream.KeyComparer, OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new TakeOrSkipWhileQueryOperatorEnumerator <TKey>( inputStream[i], _predicate, convertedIndexedPredicate, _take, operatorState, sharedBarrier, settings.CancellationState.MergedCancellationToken, inputStream.KeyComparer); } recipient.Receive(partitionedStream); }
internal override void WrapPartitionedStream <TKey>( PartitionedStream <TResult, TKey> inputStream, IPartitionedStreamRecipient <TResult> recipient, bool preferStriping, QuerySettings settings) { int partitionCount = inputStream.PartitionCount; PartitionedStream <TResult, int> listInputStream; if (m_prematureMerge) { ListQueryResults <TResult> results = ExecuteAndCollectResults(inputStream, partitionCount, Child.OutputOrdered, preferStriping, settings); listInputStream = results.GetPartitionedStream(); } else { Contract.Assert(typeof(int) == typeof(TKey)); listInputStream = (PartitionedStream <TResult, int>)(object) inputStream; } // Create shared data. One is an index that represents the lowest false value found, // while the other is a latch used as a barrier. Shared <int> sharedLowFalse = new Shared <int>(-1); // Note that -1 is a sentinel to mean "not set yet". CountdownEvent sharedBarrier = new CountdownEvent(partitionCount); PartitionedStream <TResult, int> partitionedStream = new PartitionedStream <TResult, int>(partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new TakeOrSkipWhileQueryOperatorEnumerator( listInputStream[i], m_predicate, m_indexedPredicate, m_take, sharedLowFalse, sharedBarrier, settings.CancellationState.MergedCancellationToken); } recipient.Receive(partitionedStream); }
internal override void WrapPartitionedStream <TKey>(PartitionedStream <TResult, TKey> inputStream, IPartitionedStreamRecipient <TResult> recipient, bool preferStriping, QuerySettings settings) { PartitionedStream <TResult, int> stream; int partitionCount = inputStream.PartitionCount; if (this.m_prematureMerge) { stream = QueryOperator <TResult> .ExecuteAndCollectResults <TKey>(inputStream, partitionCount, base.Child.OutputOrdered, preferStriping, settings).GetPartitionedStream(); } else { stream = (PartitionedStream <TResult, int>)inputStream; } Shared <int> sharedLowFalse = new Shared <int>(-1); CountdownEvent sharedBarrier = new CountdownEvent(partitionCount); PartitionedStream <TResult, int> partitionedStream = new PartitionedStream <TResult, int>(partitionCount, Util.GetDefaultComparer <int>(), this.OrdinalIndexState); for (int i = 0; i < partitionCount; i++) { partitionedStream[i] = new TakeOrSkipWhileQueryOperatorEnumerator <TResult>(stream[i], this.m_predicate, this.m_indexedPredicate, this.m_take, sharedLowFalse, sharedBarrier, settings.CancellationState.MergedCancellationToken); } recipient.Receive <int>(partitionedStream); }