Пример #1
0
        /// <summary>
        /// Determines the order index state for the output operator
        /// </summary>
        private void InitOrderIndexState()
        {
            // SkipWhile/TakeWhile needs an increasing index. However, if the predicate expression depends on the index,
            // the index needs to be correct, not just increasing.

            OrdinalIndexState requiredIndexState = OrdinalIndexState.Increasing;
            OrdinalIndexState childIndexState    = Child.OrdinalIndexState;

            if (_indexedPredicate != null)
            {
                requiredIndexState = OrdinalIndexState.Correct;
                _limitsParallelism = childIndexState == OrdinalIndexState.Increasing;
            }

            OrdinalIndexState indexState = ExchangeUtilities.Worse(childIndexState, OrdinalIndexState.Correct);

            if (indexState.IsWorseThan(requiredIndexState))
            {
                _prematureMerge = true;
            }

            if (!_take)
            {
                // If the index was correct, now it is only increasing.
                indexState = indexState.Worse(OrdinalIndexState.Increasing);
            }

            SetOrdinalIndexState(indexState);
        }
        private readonly TSource _defaultValue; // The default value to use (if empty).

        //---------------------------------------------------------------------------------------
        // Initializes a new reverse operator.
        //
        // Arguments:
        //     child                - the child whose data we will reverse
        //

        internal DefaultIfEmptyQueryOperator(IEnumerable <TSource> child, TSource defaultValue)
            : base(child)
        {
            Debug.Assert(child != null, "child data source cannot be null");
            _defaultValue = defaultValue;
            SetOrdinalIndexState(ExchangeUtilities.Worse(Child.OrdinalIndexState, OrdinalIndexState.Correct));
        }
        /// <summary>
        /// Determines the order index state for the output operator
        /// </summary>
        private OrdinalIndexState OutputOrderIndexState()
        {
            // SkipWhile/TakeWhile needs an increasing index. However, if the predicate expression depends on the index,
            // the index needs to be correct, not just increasing.

            OrdinalIndexState requiredIndexState = OrdinalIndexState.Increasing;

            if (m_indexedPredicate != null)
            {
                requiredIndexState = OrdinalIndexState.Correct;
            }

            OrdinalIndexState indexState = ExchangeUtilities.Worse(Child.OrdinalIndexState, OrdinalIndexState.Correct);

            if (indexState.IsWorseThan(requiredIndexState))
            {
                m_prematureMerge = true;
            }

            if (!m_take)
            {
                // If the index was correct, now it is only increasing.
                indexState = indexState.Worse(OrdinalIndexState.Increasing);
            }
            return(indexState);
        }
Пример #4
0
        //---------------------------------------------------------------------------------------
        // Initializes a new where operator.
        //
        // Arguments:
        //    child         - the child operator or data source from which to pull data
        //    predicate     - a delegate representing the predicate function
        //
        // Assumptions:
        //    predicate must be non null.
        //

        internal WhereQueryOperator(IEnumerable <TInputOutput> child, Func <TInputOutput, bool> predicate)
            : base(child)
        {
            Debug.Assert(child != null, "child data source cannot be null");
            Debug.Assert(predicate != null, "need a filter function");

            SetOrdinalIndexState(
                ExchangeUtilities.Worse(Child.OrdinalIndexState, OrdinalIndexState.Increasing));

            _predicate = predicate;
        }
        private readonly bool _prematureMergeRight; // Whether to prematurely merge the right data source

        //---------------------------------------------------------------------------------------
        // Initializes a new concatenation operator.
        //
        // Arguments:
        //     child                - the child whose data we will reverse
        //

        internal ConcatQueryOperator(ParallelQuery <TSource> firstChild, ParallelQuery <TSource> secondChild)
            : base(firstChild, secondChild)
        {
            Debug.Assert(firstChild != null, "first child data source cannot be null");
            Debug.Assert(secondChild != null, "second child data source cannot be null");
            _outputOrdered = LeftChild.OutputOrdered || RightChild.OutputOrdered;

            _prematureMergeLeft  = LeftChild.OrdinalIndexState.IsWorseThan(OrdinalIndexState.Increasing);
            _prematureMergeRight = RightChild.OrdinalIndexState.IsWorseThan(OrdinalIndexState.Increasing);

            if ((LeftChild.OrdinalIndexState == OrdinalIndexState.Indexable) &&
                (RightChild.OrdinalIndexState == OrdinalIndexState.Indexable))
            {
                SetOrdinalIndex(OrdinalIndexState.Indexable);
            }
            else
            {
                SetOrdinalIndex(
                    ExchangeUtilities.Worse(OrdinalIndexState.Increasing,
                                            ExchangeUtilities.Worse(LeftChild.OrdinalIndexState, RightChild.OrdinalIndexState)));
            }
        }