コード例 #1
0
        //---------------------------------------------------------------------------------------
        // This is a helper method. WrapPartitionedStream decides what type TKey is going
        // to be, and then call this method with that key as a generic parameter.
        //

        private void WrapPartitionedStreamHelperOrdered <TKey>(
            PartitionedStream <Pair <TSource, TGroupKey>, TKey> hashStream,
            IPartitionedStreamRecipient <IGrouping <TGroupKey, TElement> > recipient,
            CancellationToken cancellationToken)
        {
            int partitionCount = hashStream.PartitionCount;
            PartitionedStream <IGrouping <TGroupKey, TElement>, TKey> outputStream =
                new PartitionedStream <IGrouping <TGroupKey, TElement>, TKey>(partitionCount, hashStream.KeyComparer, OrdinalIndexState.Shuffled);

            // If there is no element selector, we return a special identity enumerator. Otherwise,
            // we return one that will apply the element selection function during enumeration.

            IComparer <TKey> orderComparer = hashStream.KeyComparer;

            for (int i = 0; i < partitionCount; i++)
            {
                if (_elementSelector == null)
                {
                    Debug.Assert(typeof(TSource) == typeof(TElement));

                    var enumerator = new OrderedGroupByIdentityQueryOperatorEnumerator <TSource, TGroupKey, TKey>(
                        hashStream[i], _keySelector, _keyComparer, orderComparer, cancellationToken);

                    outputStream[i] = (QueryOperatorEnumerator <IGrouping <TGroupKey, TElement>, TKey>)(object) enumerator;
                }
                else
                {
                    outputStream[i] = new OrderedGroupByElementSelectorQueryOperatorEnumerator <TSource, TGroupKey, TElement, TKey>(
                        hashStream[i], _keySelector, _elementSelector, _keyComparer, orderComparer,
                        cancellationToken);
                }
            }

            recipient.Receive(outputStream);
        }
コード例 #2
0
        private void WrapPartitionedStreamHelperOrdered <TKey>(PartitionedStream <Pair <TSource, TGroupKey>, TKey> hashStream, IPartitionedStreamRecipient <IGrouping <TGroupKey, TElement> > recipient, CancellationToken cancellationToken)
        {
            int partitionCount = hashStream.PartitionCount;
            PartitionedStream <IGrouping <TGroupKey, TElement>, TKey> partitionedStream = new PartitionedStream <IGrouping <TGroupKey, TElement>, TKey>(partitionCount, hashStream.KeyComparer, OrdinalIndexState.Shuffled);
            IComparer <TKey> keyComparer = hashStream.KeyComparer;

            for (int i = 0; i < partitionCount; i++)
            {
                if (this.m_elementSelector == null)
                {
                    OrderedGroupByIdentityQueryOperatorEnumerator <TSource, TGroupKey, TKey> enumerator = new OrderedGroupByIdentityQueryOperatorEnumerator <TSource, TGroupKey, TKey>(hashStream[i], this.m_keySelector, this.m_keyComparer, keyComparer, cancellationToken);
                    partitionedStream[i] = (QueryOperatorEnumerator <IGrouping <TGroupKey, TElement>, TKey>)enumerator;
                }
                else
                {
                    partitionedStream[i] = new OrderedGroupByElementSelectorQueryOperatorEnumerator <TSource, TGroupKey, TElement, TKey>(hashStream[i], this.m_keySelector, this.m_elementSelector, this.m_keyComparer, keyComparer, cancellationToken);
                }
            }
            recipient.Receive <TKey>(partitionedStream);
        }