Example #1
0
        private void WrapHelper <TKey>(
            PartitionedStream <TSource, TKey> inputStream, IPartitionedStreamRecipient <TSource> recipient, QuerySettings settings)
        {
            int partitionCount = inputStream.PartitionCount;

            if (ParallelEnumerable.SinglePartitionMode)
            {
                Debug.Assert(partitionCount == 1);
            }

            // Generate the shared data.
            FirstQueryOperatorState <TKey> operatorState = new FirstQueryOperatorState <TKey>();
            CountdownEvent sharedBarrier = new CountdownEvent(partitionCount);

            PartitionedStream <TSource, int> outputStream = new PartitionedStream <TSource, int>(
                partitionCount, Util.GetDefaultComparer <int>(), OrdinalIndexState.Shuffled);

            for (int i = 0; i < partitionCount; i++)
            {
                outputStream[i] = new FirstQueryOperatorEnumerator <TKey>(
                    inputStream[i], _predicate, operatorState, sharedBarrier,
                    settings.CancellationState.MergedCancellationToken, inputStream.KeyComparer, i);
            }

            recipient.Receive(outputStream);
        }
Example #2
0
            private readonly IComparer <TKey> _keyComparer;                 // Comparer for the order keys

            //---------------------------------------------------------------------------------------
            // Instantiates a new enumerator.
            //

            internal FirstQueryOperatorEnumerator(
                QueryOperatorEnumerator <TSource, TKey> source, Func <TSource, bool>?predicate,
                FirstQueryOperatorState <TKey> operatorState, CountdownEvent sharedBarrier, CancellationToken cancellationToken,
                IComparer <TKey> keyComparer, int partitionId)
            {
                Debug.Assert(source != null);
                Debug.Assert(operatorState != null);
                Debug.Assert(sharedBarrier != null);
                Debug.Assert(keyComparer != null);

                _source            = source;
                _predicate         = predicate;
                _operatorState     = operatorState;
                _sharedBarrier     = sharedBarrier;
                _cancellationToken = cancellationToken;
                _keyComparer       = keyComparer;
                _partitionId       = partitionId;
            }