public OrderedGroupJoinBaseHashBuilder(
                HashLookup <THashKey, GroupKeyData> baseLookup,
                IComparer <TOrderKey> orderKeyComparer)
            {
                Debug.Assert(baseLookup != null);

                _base             = baseLookup;
                _orderKeyComparer = orderKeyComparer;
            }
        public override HashJoinHashLookup <THashKey, IEnumerable <TElement>, int> BuildHashLookup(CancellationToken cancellationToken)
        {
            HashLookup <THashKey, ListChunk <TElement> > lookup = new HashLookup <THashKey, ListChunk <TElement> >(_keyComparer);
            GroupJoinBaseHashBuilder baseHashBuilder            = new GroupJoinBaseHashBuilder(lookup);

            BuildBaseHashLookup(_dataSource, baseHashBuilder, cancellationToken);

            return(new GroupJoinHashLookup(lookup));
        }
        public override HashJoinHashLookup <THashKey, TElement, TOrderKey> BuildHashLookup(CancellationToken cancellationToken)
        {
            HashLookup <THashKey, HashLookupValueList <TElement, TOrderKey> > lookup =
                new HashLookup <THashKey, HashLookupValueList <TElement, TOrderKey> >(_keyComparer);
            JoinBaseHashBuilder baseHashBuilder = new JoinBaseHashBuilder(lookup);

            BuildBaseHashLookup(_dataSource, baseHashBuilder, cancellationToken);

            return(new JoinHashLookup(lookup));
        }
        //-----------------------------------------------------------------------------------
        // Builds the hash lookup, transforming from TSource to TElement through whatever means is appropriate.
        //

        protected override HashLookup <Wrapper <TGroupKey>, GroupKeyData> BuildHashLookup()
        {
            HashLookup <Wrapper <TGroupKey>, GroupKeyData> hashLookup = new HashLookup <Wrapper <TGroupKey>, GroupKeyData>(
                new WrapperEqualityComparer <TGroupKey>(_keyComparer));

            Pair <TSource, TGroupKey> sourceElement = default(Pair <TSource, TGroupKey>);
            TOrderKey sourceOrderKey = default(TOrderKey) !;
            int       i = 0;

            while (_source.MoveNext(ref sourceElement, ref sourceOrderKey))
            {
                if ((i++ & CancellationState.POLL_INTERVAL) == 0)
                {
                    _cancellationToken.ThrowIfCancellationRequested();
                }
                ;

                // Generate a key and place it into the hashtable.
                Wrapper <TGroupKey> key = new Wrapper <TGroupKey>(sourceElement.Second);

                // If the key already exists, we just append it to the existing list --
                // otherwise we will create a new one and add it to that instead.
                GroupKeyData?currentValue = null;
                if (hashLookup.TryGetValue(key, ref currentValue))
                {
                    if (_orderComparer.Compare(sourceOrderKey, currentValue._orderKey) < 0)
                    {
                        currentValue._orderKey = sourceOrderKey;
                    }
                }
                else
                {
                    currentValue = new GroupKeyData(sourceOrderKey, key.Value, _orderComparer);

                    hashLookup.Add(key, currentValue);
                }

                Debug.Assert(currentValue != null);

                // Call to the base class to yield the current value.
                currentValue._grouping.Add(_elementSelector(sourceElement.First), sourceOrderKey);
            }

            // Sort the elements within each group
            for (int j = 0; j < hashLookup.Count; j++)
            {
                hashLookup[j].Value._grouping.DoneAdding();
            }

            return(hashLookup);
        }
        public override HashJoinHashLookup <THashKey, IEnumerable <TElement>, Pair <bool, TOrderKey> > BuildHashLookup(CancellationToken cancellationToken)
        {
            HashLookup <THashKey, GroupKeyData> lookup          = new HashLookup <THashKey, GroupKeyData>(_keyComparer);
            OrderedGroupJoinBaseHashBuilder     baseHashBuilder = new OrderedGroupJoinBaseHashBuilder(lookup, _orderKeyComparer);

            BuildBaseHashLookup(_dataSource, baseHashBuilder, cancellationToken);

            for (int i = 0; i < lookup.Count; i++)
            {
                lookup[i].Value._grouping.DoneAdding();
            }

            return(new OrderedGroupJoinHashLookup(lookup));
        }
        //-----------------------------------------------------------------------------------
        // Builds the hash lookup, transforming from TSource to TElement through whatever means is appropriate.
        //

        protected override HashLookup <Wrapper <TGroupKey>, ListChunk <TElement> > BuildHashLookup()
        {
            HashLookup <Wrapper <TGroupKey>, ListChunk <TElement> > hashlookup =
                new HashLookup <Wrapper <TGroupKey>, ListChunk <TElement> >(new WrapperEqualityComparer <TGroupKey>(_keyComparer));

            Pair <TSource, TGroupKey> sourceElement = default(Pair <TSource, TGroupKey>);
            TOrderKey sourceKeyUnused = default(TOrderKey) !;
            int       i = 0;

            while (_source.MoveNext(ref sourceElement, ref sourceKeyUnused))
            {
                if ((i++ & CancellationState.POLL_INTERVAL) == 0)
                {
                    _cancellationToken.ThrowIfCancellationRequested();
                }
                ;

                // Generate a key and place it into the hashtable.
                Wrapper <TGroupKey> key = new Wrapper <TGroupKey>(sourceElement.Second);

                // If the key already exists, we just append it to the existing list --
                // otherwise we will create a new one and add it to that instead.
                ListChunk <TElement>?currentValue = null;
                if (!hashlookup.TryGetValue(key, ref currentValue))
                {
                    const int INITIAL_CHUNK_SIZE = 2;
                    currentValue = new ListChunk <TElement>(INITIAL_CHUNK_SIZE);
                    hashlookup.Add(key, currentValue);
                }
                Debug.Assert(currentValue != null);

                // Call to the base class to yield the current value.
                currentValue.Add(_elementSelector(sourceElement.First));
            }

            return(hashlookup);
        }
Exemple #7
0
        protected override HashLookup <Wrapper <TGroupKey>, ListChunk <TSource> > BuildHashLookup()
        {
            HashLookup <Wrapper <TGroupKey>, ListChunk <TSource> > lookup = new HashLookup <Wrapper <TGroupKey>, ListChunk <TSource> >(new WrapperEqualityComparer <TGroupKey>(base.m_keyComparer));
            Pair <TSource, TGroupKey> currentElement = new Pair <TSource, TGroupKey>();
            TOrderKey currentKey = default(TOrderKey);
            int       num        = 0;

            while (base.m_source.MoveNext(ref currentElement, ref currentKey))
            {
                if ((num++ & 0x3f) == 0)
                {
                    CancellationState.ThrowIfCanceled(base.m_cancellationToken);
                }
                Wrapper <TGroupKey> key   = new Wrapper <TGroupKey>(currentElement.Second);
                ListChunk <TSource> chunk = null;
                if (!lookup.TryGetValue(key, ref chunk))
                {
                    chunk = new ListChunk <TSource>(2);
                    lookup.Add(key, chunk);
                }
                chunk.Add(currentElement.First);
            }
            return(lookup);
        }
        internal GroupJoinHashLookup(HashLookup <THashKey, TBaseElement> baseLookup)
        {
            Debug.Assert(baseLookup != null);

            _base = baseLookup;
        }
 internal OrderedGroupJoinHashLookup(HashLookup <THashKey, GroupKeyData> lookup)
     : base(lookup)
 {
 }
 internal GroupJoinHashLookup(HashLookup <THashKey, ListChunk <TElement> > lookup)
     : base(lookup)
 {
 }
            public GroupJoinBaseHashBuilder(HashLookup <THashKey, ListChunk <TElement> > baseLookup)
            {
                Debug.Assert(baseLookup != null);

                _base = baseLookup;
            }
            internal JoinHashLookup(HashLookup <THashKey, HashLookupValueList <TElement, TOrderKey> > baseLookup)
            {
                Debug.Assert(baseLookup != null);

                _base = baseLookup;
            }
            public JoinBaseHashBuilder(HashLookup <THashKey, HashLookupValueList <TElement, TOrderKey> > baseLookup)
            {
                Debug.Assert(baseLookup != null);

                _base = baseLookup;
            }
Exemple #14
0
        protected override HashLookup <Wrapper <TGroupKey>, OrderedGroupByQueryOperatorEnumerator <TSource, TGroupKey, TSource, TOrderKey> .GroupKeyData> BuildHashLookup()
        {
            HashLookup <Wrapper <TGroupKey>, OrderedGroupByQueryOperatorEnumerator <TSource, TGroupKey, TSource, TOrderKey> .GroupKeyData> lookup = new HashLookup <Wrapper <TGroupKey>, OrderedGroupByQueryOperatorEnumerator <TSource, TGroupKey, TSource, TOrderKey> .GroupKeyData>(new WrapperEqualityComparer <TGroupKey>(base.m_keyComparer));
            Pair <TSource, TGroupKey> currentElement = new Pair <TSource, TGroupKey>();
            TOrderKey currentKey = default(TOrderKey);
            int       num        = 0;

            while (base.m_source.MoveNext(ref currentElement, ref currentKey))
            {
                if ((num++ & 0x3f) == 0)
                {
                    CancellationState.ThrowIfCanceled(base.m_cancellationToken);
                }
                Wrapper <TGroupKey> key = new Wrapper <TGroupKey>(currentElement.Second);
                OrderedGroupByQueryOperatorEnumerator <TSource, TGroupKey, TSource, TOrderKey> .GroupKeyData data = null;
                if (lookup.TryGetValue(key, ref data))
                {
                    if (base.m_orderComparer.Compare(currentKey, data.m_orderKey) < 0)
                    {
                        data.m_orderKey = currentKey;
                    }
                }
                else
                {
                    data = new OrderedGroupByQueryOperatorEnumerator <TSource, TGroupKey, TSource, TOrderKey> .GroupKeyData(currentKey, key.Value, base.m_orderComparer);

                    lookup.Add(key, data);
                }
                data.m_grouping.Add(currentElement.First, currentKey);
            }
            for (int i = 0; i < lookup.Count; i++)
            {
                KeyValuePair <Wrapper <TGroupKey>, OrderedGroupByQueryOperatorEnumerator <TSource, TGroupKey, TSource, TOrderKey> .GroupKeyData> pair2 = lookup[i];
                pair2.Value.m_grouping.DoneAdding();
            }
            return(lookup);
        }