Exemplo n.º 1
0
        internal override void WrapPartitionedStream <TKey>(
            PartitionedStream <TResult, TKey> inputStream, IPartitionedStreamRecipient <TResult> recipient, bool preferStriping, QuerySettings settings)
        {
            Contract.Assert(Child.OrdinalIndexState != OrdinalIndexState.Indexible, "Don't take this code path if the child is indexible.");

            PartitionedStream <TResult, int> inputIntStream;

            // If the index is not at least increasing, we need to reindex.
            if (m_prematureMerge)
            {
                ListQueryResults <TResult> results = ExecuteAndCollectResults(
                    inputStream, inputStream.PartitionCount, Child.OutputOrdered, preferStriping, settings);
                inputIntStream = results.GetPartitionedStream();
            }
            else
            {
                Contract.Assert(typeof(TKey) == typeof(int));
                inputIntStream = (PartitionedStream <TResult, int>)((object)inputStream);
            }

            int partitionCount = inputStream.PartitionCount;
            FixedMaxHeap <int> sharedIndices  = new FixedMaxHeap <int>(m_count);    // an array used to track the sequence of indices leading up to the Nth index
            CountdownEvent     sharredBarrier = new CountdownEvent(partitionCount); // a barrier to synchronize before yielding

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

            for (int i = 0; i < partitionCount; i++)
            {
                outputStream[i] = new TakeOrSkipQueryOperatorEnumerator(
                    inputIntStream[i], m_count, m_take, sharedIndices, sharredBarrier, settings.CancellationState.MergedCancellationToken);
            }

            recipient.Receive(outputStream);
        }
Exemplo n.º 2
0
 internal TakeOrSkipQueryOperatorEnumerator(QueryOperatorEnumerator <TResult, int> source, int count, bool take, FixedMaxHeap <int> sharedIndices, CountdownEvent sharedBarrier, CancellationToken cancellationToken)
 {
     this.m_source            = source;
     this.m_count             = count;
     this.m_take              = take;
     this.m_sharedIndices     = sharedIndices;
     this.m_sharedBarrier     = sharedBarrier;
     this.m_cancellationToken = cancellationToken;
 }
            internal OrderedPipeliningMergeEnumerator(OrderPreservingPipeliningMergeHelper <TOutput> mergeHelper) : base(mergeHelper.m_taskGroupState)
            {
                int partitionCount = mergeHelper.m_partitions.PartitionCount;

                this.m_mergeHelper         = mergeHelper;
                this.m_producerHeap        = new FixedMaxHeap <OrderPreservingPipeliningMergeHelper <TOutput> .Producer>(partitionCount, OrderPreservingPipeliningMergeHelper <TOutput> .s_producerComparer);
                this.m_privateBuffer       = new Queue <Pair <int, TOutput> > [partitionCount];
                this.m_producerNextElement = new TOutput[partitionCount];
            }
Exemplo n.º 4
0
            /// <summary>
            /// Constructor
            /// </summary>
            internal OrderedPipeliningMergeEnumerator(OrderPreservingPipeliningMergeHelper <TOutput, TKey> mergeHelper, IComparer <Producer <TKey> > producerComparer)
                : base(mergeHelper._taskGroupState)
            {
                int partitionCount = mergeHelper._partitions.PartitionCount;

                _mergeHelper         = mergeHelper;
                _producerHeap        = new FixedMaxHeap <Producer <TKey> >(partitionCount, producerComparer);
                _privateBuffer       = new Queue <Pair <TKey, TOutput> > [partitionCount];
                _producerNextElement = new TOutput[partitionCount];
            }
Exemplo n.º 5
0
            private Shared <int> m_bufferIndex;                     // Our current index within the buffer. [allocate in moveNext to avoid false-sharing]

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

            internal TakeOrSkipQueryOperatorEnumerator(
                QueryOperatorEnumerator <TResult, int> source, int count, bool take,
                FixedMaxHeap <int> sharedIndices, CountdownEvent sharedBarrier, CancellationToken cancellationToken)
            {
                Contract.Assert(source != null);
                Contract.Assert(sharedIndices != null);
                Contract.Assert(sharedBarrier != null);
                Contract.Assert(sharedIndices.Size == count);

                m_source            = source;
                m_count             = count;
                m_take              = take;
                m_sharedIndices     = sharedIndices;
                m_sharedBarrier     = sharedBarrier;
                m_cancellationToken = cancellationToken;
            }
Exemplo n.º 6
0
            private Shared <int>?_bufferIndex;                     // Our current index within the buffer. [allocate in moveNext to avoid false-sharing]

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

            internal TakeOrSkipQueryOperatorEnumerator(
                QueryOperatorEnumerator <TResult, TKey> source, bool take,
                FixedMaxHeap <TKey> sharedIndices, CountdownEvent sharedBarrier, CancellationToken cancellationToken,
                IComparer <TKey> keyComparer)
            {
                Debug.Assert(source != null);
                Debug.Assert(sharedIndices != null);
                Debug.Assert(sharedBarrier != null);
                Debug.Assert(keyComparer != null);

                _source            = source;
                _count             = sharedIndices.Size;
                _take              = take;
                _sharedIndices     = sharedIndices;
                _sharedBarrier     = sharedBarrier;
                _cancellationToken = cancellationToken;
                _keyComparer       = keyComparer;
            }
Exemplo n.º 7
0
        private void WrapHelper <TKey>(PartitionedStream <TResult, TKey> inputStream, IPartitionedStreamRecipient <TResult> recipient, QuerySettings settings)
        {
            int partitionCount = inputStream.PartitionCount;
            FixedMaxHeap <TKey> sharedIndices = new FixedMaxHeap <TKey>(_count, inputStream.KeyComparer); // an array used to track the sequence of indices leading up to the Nth index
            CountdownEvent      sharedBarrier = new CountdownEvent(partitionCount);                       // a barrier to synchronize before yielding

            PartitionedStream <TResult, TKey> outputStream =
                new PartitionedStream <TResult, TKey>(partitionCount, inputStream.KeyComparer, OrdinalIndexState);

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

            recipient.Receive(outputStream);
        }
Exemplo n.º 8
0
        internal override void WrapPartitionedStream <TKey>(PartitionedStream <TResult, TKey> inputStream, IPartitionedStreamRecipient <TResult> recipient, bool preferStriping, QuerySettings settings)
        {
            PartitionedStream <TResult, int> stream;

            if (this.m_prematureMerge)
            {
                stream = QueryOperator <TResult> .ExecuteAndCollectResults <TKey>(inputStream, inputStream.PartitionCount, base.Child.OutputOrdered, preferStriping, settings).GetPartitionedStream();
            }
            else
            {
                stream = (PartitionedStream <TResult, int>)inputStream;
            }
            int partitionCount = inputStream.PartitionCount;
            FixedMaxHeap <int> sharedIndices = new FixedMaxHeap <int>(this.m_count);
            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 TakeOrSkipQueryOperatorEnumerator <TResult>(stream[i], this.m_count, this.m_take, sharedIndices, sharedBarrier, settings.CancellationState.MergedCancellationToken);
            }
            recipient.Receive <int>(partitionedStream);
        }