예제 #1
0
        //---------------------------------------------------------------------------------------
        // MoveNext will invoke the entire query sub-tree, accumulating results into a hash-
        // table, upon the first call. Then for the first call and all subsequent calls, we will
        // just enumerate the key-set from the hash-table, retrieving groupings of key-elements.
        //

        internal override bool MoveNext(ref IGrouping <TGroupKey, TElement> currentElement, ref TOrderKey currentKey)
        {
            Debug.Assert(_source != null);

            // Lazy-init the mutable state. This also means we haven't yet built our lookup of
            // groupings, so we can go ahead and do that too.
            Mutables mutables = _mutables;

            if (mutables == null)
            {
                mutables = _mutables = new Mutables();

                // Build the hash lookup and start enumerating the lookup at the beginning.
                mutables._hashLookup = BuildHashLookup();
                Debug.Assert(mutables._hashLookup != null);
                mutables._hashLookupIndex = -1;
            }

            // Now, with a hash lookup in hand, we just enumerate the keys. So long
            // as the key-value lookup has elements, we have elements.
            if (++mutables._hashLookupIndex < mutables._hashLookup.Count)
            {
                currentElement = new GroupByGrouping <TGroupKey, TElement>(
                    mutables._hashLookup[mutables._hashLookupIndex]);
                return(true);
            }

            return(false);
        }
        internal override bool MoveNext(ref IGrouping <TGroupKey, TElement> currentElement, ref TOrderKey currentKey)
        {
            Mutables <TSource, TGroupKey, TElement, TOrderKey> mutables = this.m_mutables;

            if (mutables == null)
            {
                mutables = this.m_mutables = new Mutables <TSource, TGroupKey, TElement, TOrderKey>();
                mutables.m_hashLookup      = this.BuildHashLookup();
                mutables.m_hashLookupIndex = -1;
            }
            if (++mutables.m_hashLookupIndex < mutables.m_hashLookup.Count)
            {
                currentElement = new GroupByGrouping <TGroupKey, TElement>(mutables.m_hashLookup[mutables.m_hashLookupIndex]);
                return(true);
            }
            return(false);
        }