예제 #1
0
        /// <summary>
        /// Enqueue
        /// </summary>
        protected internal void Enqueue(T value)
        {
            EventHandler <SlidingWindowChangedEventArgs <T> > changed = Changed;

            Optional <T> currentPrevious = m_Buffer.Count > 0
        ? new Optional <T>(Current)
        : new Optional <T>();

            bool wasCompleted = IsCompleted;

            Optional <T> itemRemoved;

            if (m_Buffer.Count < m_Buffer.Capacity)
            {
                m_Buffer.Add(value);
                itemRemoved = new Optional <T>();
            }
            else
            {
                itemRemoved             = new Optional <T>(m_Buffer[m_InsertIndex]);
                m_Buffer[m_InsertIndex] = value;
            }

            m_InsertIndex = (m_InsertIndex + 1) % m_Buffer.Capacity;

            if (changed != null)
            {
                SlidingWindowChangedEventArgs <T> args = new SlidingWindowChangedEventArgs <T>(
                    this,
                    new Optional <T>(Current),
                    currentPrevious,
                    new Optional <T>(value),
                    itemRemoved,
                    IsCompleted,
                    wasCompleted
                    );

                changed(this, args);
            }
        }
예제 #2
0
        /// <summary>
        /// Dequeue if possible
        /// </summary>
        protected internal bool Dequeue()
        {
            if (AfterCount <= 0)
            {
                return(false);
            }

            bool wasCompleted = IsCompleted;

            Optional <T> currentPrevious = m_Buffer.Count > 0
        ? new Optional <T>(Current)
        : new Optional <T>();

            Optional <T> itemRemoved = new Optional <T>(this[-BeforeCount]);

            m_Deleted += 1;

            EventHandler <SlidingWindowChangedEventArgs <T> > changed = Changed;

            if (changed != null)
            {
                SlidingWindowChangedEventArgs <T> args = new SlidingWindowChangedEventArgs <T>(
                    this,
                    new Optional <T>(Current),
                    currentPrevious,
                    new Optional <T>(),
                    itemRemoved,
                    IsCompleted,
                    wasCompleted
                    );

                changed(this, args);
            }

            return(true);
        }