//--------------------------------------------------------------------------------------- // 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 WrapPartitionedStreamHelper <TIgnoreKey, 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. for (int i = 0; i < partitionCount; i++) { if (_elementSelector == null) { Debug.Assert(typeof(TSource) == typeof(TElement)); var enumerator = new GroupByIdentityQueryOperatorEnumerator <TSource, TGroupKey, TKey>( hashStream[i], _keyComparer, cancellationToken); outputStream[i] = (QueryOperatorEnumerator <IGrouping <TGroupKey, TElement>, TKey>)(object) enumerator; } else { outputStream[i] = new GroupByElementSelectorQueryOperatorEnumerator <TSource, TGroupKey, TElement, TKey>( hashStream[i], _keyComparer, _elementSelector, cancellationToken); } } recipient.Receive(outputStream); }
private void WrapPartitionedStreamHelper <TIgnoreKey, 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); for (int i = 0; i < partitionCount; i++) { if (this.m_elementSelector == null) { GroupByIdentityQueryOperatorEnumerator <TSource, TGroupKey, TKey> enumerator = new GroupByIdentityQueryOperatorEnumerator <TSource, TGroupKey, TKey>(hashStream[i], this.m_keyComparer, cancellationToken); partitionedStream[i] = (QueryOperatorEnumerator <IGrouping <TGroupKey, TElement>, TKey>)enumerator; } else { partitionedStream[i] = new GroupByElementSelectorQueryOperatorEnumerator <TSource, TGroupKey, TElement, TKey>(hashStream[i], this.m_keyComparer, this.m_elementSelector, cancellationToken); } } recipient.Receive <TKey>(partitionedStream); }