示例#1
0
        /// <summary>
        ///     Adds item to the front of the buffer
        /// </summary>
        /// <param name="item">Item to add</param>
        public void PushFront(T item)
        {
            if (!IsEmpty)
            {
                IncreaseFrontIndex();
            }
            OnItemAdded?.Invoke(this, new ItemAddedEventArgs(Count - 1, item));
            if (Count == Capacity)
            {
                OnItemOverflown?.Invoke(this, new ItemOverflownEventArgs(false, _buffer[_frontItem]));
            }

            _buffer[_frontItem] = item;
            if (Count < Capacity)
            {
                Count++;
            }
        }
示例#2
0
        /// <summary>
        ///     Adds item to the back of the buffer
        /// </summary>
        /// <param name="item">Item to add</param>
        public void PushBack(T item)
        {
            if (!IsEmpty)
            {
                DecreaseBackIndex();
            }
            OnItemAdded?.Invoke(this, new ItemAddedEventArgs(0, item));
            if (Count == Capacity)
            {
                OnItemOverflown?.Invoke(this, new ItemOverflownEventArgs(true, _buffer[_backItem]));
            }

            _buffer[_backItem] = item;
            if (Count < Capacity)
            {
                Count++;
            }
        }