Exemplo n.º 1
0
            //---------------------------------------------------------------------------------------
            // MoveNext advances to the next element in the output.  While the first data source has
            // elements, this consists of just advancing through it.  After this, all partitions must
            // synchronize at a barrier and publish the maximum index N.  Finally, all partitions can
            // move on to the second data source, adding N+1 to indices in order to get the correct
            // index offset.
            //

            internal override bool MoveNext(ref TSource currentElement, ref ConcatKey <TLeftKey, TRightKey> currentKey)
            {
                Contract.Assert(m_firstSource != null);
                Contract.Assert(m_secondSource != null);

                // If we are still enumerating the first source, fetch the next item.
                if (!m_begunSecond)
                {
                    // If elements remain, just return true and continue enumerating the left.
                    TLeftKey leftKey = default(TLeftKey);
                    if (m_firstSource.MoveNext(ref currentElement, ref leftKey))
                    {
                        currentKey = ConcatKey <TLeftKey, TRightKey> .MakeLeft(leftKey);

                        return(true);
                    }
                    m_begunSecond = true;
                }

                // Now either move on to, or continue, enumerating the right data source.
                TRightKey rightKey = default(TRightKey);

                if (m_secondSource.MoveNext(ref currentElement, ref rightKey))
                {
                    currentKey = ConcatKey <TLeftKey, TRightKey> .MakeRight(rightKey);

                    return(true);
                }

                return(false);
            }
            internal override bool MoveNext(ref TInputOutput currentElement, ref ConcatKey <TLeftKey, TRightKey> currentKey)
            {
                if (this.m_outputEnumerator == null)
                {
                    IEqualityComparer <Wrapper <TInputOutput> > comparer = new WrapperEqualityComparer <TInputOutput>(this.m_comparer);
                    Dictionary <Wrapper <TInputOutput>, Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> > > dictionary = new Dictionary <Wrapper <TInputOutput>, Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> > >(comparer);
                    Pair <TInputOutput, NoKeyMemoizationRequired> pair = new Pair <TInputOutput, NoKeyMemoizationRequired>();
                    TLeftKey local = default(TLeftKey);
                    int      num   = 0;
                    while (this.m_leftSource.MoveNext(ref pair, ref local))
                    {
                        Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> > pair2;
                        if ((num++ & 0x3f) == 0)
                        {
                            CancellationState.ThrowIfCanceled(this.m_cancellationToken);
                        }
                        ConcatKey <TLeftKey, TRightKey> x = ConcatKey <TLeftKey, TRightKey> .MakeLeft(this.m_leftOrdered?local : default(TLeftKey));

                        Wrapper <TInputOutput> key = new Wrapper <TInputOutput>(pair.First);
                        if (!dictionary.TryGetValue(key, out pair2) || (this.m_keyComparer.Compare(x, pair2.Second) < 0))
                        {
                            dictionary[key] = new Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> >(pair.First, x);
                        }
                    }
                    TRightKey local2 = default(TRightKey);
                    while (this.m_rightSource.MoveNext(ref pair, ref local2))
                    {
                        Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> > pair3;
                        if ((num++ & 0x3f) == 0)
                        {
                            CancellationState.ThrowIfCanceled(this.m_cancellationToken);
                        }
                        ConcatKey <TLeftKey, TRightKey> key2 = ConcatKey <TLeftKey, TRightKey> .MakeRight(this.m_rightOrdered?local2 : default(TRightKey));

                        Wrapper <TInputOutput> wrapper2 = new Wrapper <TInputOutput>(pair.First);
                        if (!dictionary.TryGetValue(wrapper2, out pair3) || (this.m_keyComparer.Compare(key2, pair3.Second) < 0))
                        {
                            dictionary[wrapper2] = new Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> >(pair.First, key2);
                        }
                    }
                    this.m_outputEnumerator = dictionary.GetEnumerator();
                }
                if (this.m_outputEnumerator.MoveNext())
                {
                    Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> > pair4 = this.m_outputEnumerator.Current.Value;
                    currentElement = pair4.First;
                    currentKey     = pair4.Second;
                    return(true);
                }
                return(false);
            }
            internal override bool MoveNext(ref TSource currentElement, ref ConcatKey <TLeftKey, TRightKey> currentKey)
            {
                if (!this.m_begunSecond)
                {
                    TLeftKey local = default(TLeftKey);
                    if (this.m_firstSource.MoveNext(ref currentElement, ref local))
                    {
                        currentKey = ConcatKey <TLeftKey, TRightKey> .MakeLeft(local);

                        return(true);
                    }
                    this.m_begunSecond = true;
                }
                TRightKey local2 = default(TRightKey);

                if (this.m_secondSource.MoveNext(ref currentElement, ref local2))
                {
                    currentKey = ConcatKey <TLeftKey, TRightKey> .MakeRight(local2);

                    return(true);
                }
                return(false);
            }
Exemplo n.º 4
0
            //---------------------------------------------------------------------------------------
            // Walks the two data sources, left and then right, to produce the union.
            //

            internal override bool MoveNext(ref TInputOutput currentElement, ref ConcatKey currentKey)
            {
                Debug.Assert(_leftSource != null);
                Debug.Assert(_rightSource != null);

                if (_outputEnumerator == null)
                {
                    IEqualityComparer <Wrapper <TInputOutput> > wrapperComparer = new WrapperEqualityComparer <TInputOutput>(_comparer);
                    Dictionary <Wrapper <TInputOutput>, Pair>   union           =
                        new Dictionary <Wrapper <TInputOutput>, Pair>(wrapperComparer);

                    Pair     elem    = new Pair(default(TInputOutput), default(NoKeyMemoizationRequired));
                    TLeftKey leftKey = default(TLeftKey);

                    int i = 0;
                    while (_leftSource.MoveNext(ref elem, ref leftKey))
                    {
                        if ((i++ & CancellationState.POLL_INTERVAL) == 0)
                        {
                            CancellationState.ThrowIfCanceled(_cancellationToken);
                        }

                        ConcatKey key =
                            ConcatKey.MakeLeft <TLeftKey, TRightKey>(_leftOrdered ? leftKey : default(TLeftKey));
                        Pair oldEntry;
                        Wrapper <TInputOutput> wrappedElem = new Wrapper <TInputOutput>((TInputOutput)elem.First);

                        if (!union.TryGetValue(wrappedElem, out oldEntry) || _keyComparer.Compare(key, (ConcatKey)oldEntry.Second) < 0)
                        {
                            union[wrappedElem] = new Pair(elem.First, key);
                        }
                    }

                    TRightKey rightKey = default(TRightKey);
                    while (_rightSource.MoveNext(ref elem, ref rightKey))
                    {
                        if ((i++ & CancellationState.POLL_INTERVAL) == 0)
                        {
                            CancellationState.ThrowIfCanceled(_cancellationToken);
                        }

                        ConcatKey key =
                            ConcatKey.MakeRight <TLeftKey, TRightKey>(_rightOrdered ? rightKey : default(TRightKey));
                        Pair oldEntry;
                        Wrapper <TInputOutput> wrappedElem = new Wrapper <TInputOutput>((TInputOutput)elem.First);

                        if (!union.TryGetValue(wrappedElem, out oldEntry) || _keyComparer.Compare(key, (ConcatKey)oldEntry.Second) < 0)
                        {
                            union[wrappedElem] = new Pair(elem.First, key);;
                        }
                    }

                    _outputEnumerator = union.GetEnumerator();
                }

                if (_outputEnumerator.MoveNext())
                {
                    Pair current = _outputEnumerator.Current.Value;
                    currentElement = (TInputOutput)current.First;
                    currentKey     = (ConcatKey)current.Second;
                    return(true);
                }

                return(false);
            }
Exemplo n.º 5
0
            //---------------------------------------------------------------------------------------
            // Walks the two data sources, left and then right, to produce the union.
            //

            internal override bool MoveNext(ref TInputOutput currentElement, ref ConcatKey <TLeftKey, TRightKey> currentKey)
            {
                Contract.Assert(m_leftSource != null);
                Contract.Assert(m_rightSource != null);

                if (m_outputEnumerator == null)
                {
                    IEqualityComparer <Wrapper <TInputOutput> > wrapperComparer = new WrapperEqualityComparer <TInputOutput>(m_comparer);
                    Dictionary <Wrapper <TInputOutput>, Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> > > union =
                        new Dictionary <Wrapper <TInputOutput>, Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> > >(wrapperComparer);

                    Pair <TInputOutput, NoKeyMemoizationRequired> elem = default(Pair <TInputOutput, NoKeyMemoizationRequired>);
                    TLeftKey leftKey = default(TLeftKey);

                    int i = 0;
                    while (m_leftSource.MoveNext(ref elem, ref leftKey))
                    {
                        if ((i++ & CancellationState.POLL_INTERVAL) == 0)
                        {
                            CancellationState.ThrowIfCanceled(m_cancellationToken);
                        }

                        ConcatKey <TLeftKey, TRightKey> key =
                            ConcatKey <TLeftKey, TRightKey> .MakeLeft(m_leftOrdered?leftKey : default(TLeftKey));

                        Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> > oldEntry;
                        Wrapper <TInputOutput> wrappedElem = new Wrapper <TInputOutput>(elem.First);

                        if (!union.TryGetValue(wrappedElem, out oldEntry) || m_keyComparer.Compare(key, oldEntry.Second) < 0)
                        {
                            union[wrappedElem] = new Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> >(elem.First, key);
                        }
                    }

                    TRightKey rightKey = default(TRightKey);
                    while (m_rightSource.MoveNext(ref elem, ref rightKey))
                    {
                        if ((i++ & CancellationState.POLL_INTERVAL) == 0)
                        {
                            CancellationState.ThrowIfCanceled(m_cancellationToken);
                        }

                        ConcatKey <TLeftKey, TRightKey> key =
                            ConcatKey <TLeftKey, TRightKey> .MakeRight(m_rightOrdered?rightKey : default(TRightKey));

                        Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> > oldEntry;
                        Wrapper <TInputOutput> wrappedElem = new Wrapper <TInputOutput>(elem.First);

                        if (!union.TryGetValue(wrappedElem, out oldEntry) || m_keyComparer.Compare(key, oldEntry.Second) < 0)
                        {
                            union[wrappedElem] = new Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> >(elem.First, key);;
                        }
                    }

                    m_outputEnumerator = union.GetEnumerator();
                }

                if (m_outputEnumerator.MoveNext())
                {
                    Pair <TInputOutput, ConcatKey <TLeftKey, TRightKey> > current = m_outputEnumerator.Current.Value;
                    currentElement = current.First;
                    currentKey     = current.Second;
                    return(true);
                }

                return(false);
            }