private Pair <IEnumerable <TElement>, TOrderKey> GetValueList(THashKey key)
        {
            TBaseElement baseValue = default(TBaseElement) !;

            if (_base.TryGetValue(key, ref baseValue !))
            {
                return(CreateValuePair(baseValue));
            }
            else
            {
                return(new Pair <IEnumerable <TElement>, TOrderKey>(ParallelEnumerable.Empty <TElement>(), EmptyValueKey));
            }
        }
        //-----------------------------------------------------------------------------------
        // 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 bool Add(THashKey hashKey, TElement element, TOrderKey orderKey)
            {
                bool hasCollision = true;

                ListChunk <TElement>?currentValue = default(ListChunk <TElement>);

                if (!_base.TryGetValue(hashKey, ref currentValue))
                {
                    const int INITIAL_CHUNK_SIZE = 2;
                    currentValue = new ListChunk <TElement>(INITIAL_CHUNK_SIZE);
                    _base.Add(hashKey, currentValue);
                    hasCollision = false;
                }

                currentValue.Add(element);

                return(hasCollision);
            }
            public bool Add(THashKey hashKey, TElement element, TOrderKey orderKey)
            {
                HashLookupValueList <TElement, TOrderKey> currentValue = default(HashLookupValueList <TElement, TOrderKey>);

                if (!_base.TryGetValue(hashKey, ref currentValue))
                {
                    currentValue = new HashLookupValueList <TElement, TOrderKey>(element, orderKey);
                    _base.Add(hashKey, currentValue);
                    return(false);
                }
                else
                {
                    if (currentValue.Add(element, orderKey))
                    {
                        // We need to re-store this element because the pair is a value type.
                        _base[hashKey] = currentValue;
                    }
                    return(true);
                }
            }
            public bool Add(THashKey hashKey, TElement element, TOrderKey orderKey)
            {
                bool hasCollision = true;

                GroupKeyData?currentValue = default(GroupKeyData);

                if (!_base.TryGetValue(hashKey, ref currentValue))
                {
                    currentValue = new GroupKeyData(orderKey, hashKey, _orderKeyComparer);
                    _base.Add(hashKey, currentValue);
                    hasCollision = false;
                }

                currentValue._grouping.Add(element, orderKey);
                if (_orderKeyComparer.Compare(orderKey, currentValue._orderKey) < 0)
                {
                    currentValue._orderKey = orderKey;
                }

                return(hasCollision);
            }
        //-----------------------------------------------------------------------------------
        // 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);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
 public override bool TryGetValue(THashKey key, ref HashLookupValueList <TElement, TOrderKey> value)
 {
     return(_base.TryGetValue(key, ref value));
 }