Пример #1
0
        public bool MoveNext()
        {
            // just pass through in this case, don't ever allocate
            //   a StructQueue
            if (InnerCount == 0)
            {
                var ret = Inner.MoveNext();
                if (ret)
                {
                    Current = Inner.Current;
                }

                return(ret);
            }

            if (Queue.IsDefaultValue())
            {
                Queue.Initialize();
            }

            // Advance in inner...
            while (Inner.MoveNext())
            {
                Queue.Enqueue(Inner.Current);

                // until we've got Count + 1 Elements....
                if (Queue.Count > InnerCount)
                {
                    // then take the first element out and yield it
                    //   leaving us with Count elements
                    Current = Queue.Dequeue();
                    return(true);
                }
            }

            // so when we fall through we've either got Count elements or fewer in the Queue
            return(false);
        }
Пример #2
0
        public bool MoveNext()
        {
            if (InnerCount == 0)
            {
                return(false);
            }

            if (Queue.IsDefaultValue())
            {
                Queue.Initialize(InnerCount);

                // advance until we exhaust the thing...
                while (Inner.MoveNext())
                {
                    // if we've hit size, pop oldest and push this latest
                    if (Queue.Count == InnerCount)
                    {
                        Queue.DequeueAndEnqueue(Inner.Current);
                    }
                    else
                    {
                        // otherwise, just keep pushing
                        Queue.Enqueue(Inner.Current);
                    }
                }
            }

            // yield everything in Queue
            if (Queue.Count > 0)
            {
                Current = Queue.Dequeue();
                return(true);
            }

            return(false);
        }