Пример #1
0
        /// <summary>
        /// Dequeue an item.
        /// </summary>
        /// <exception cref="InvalidOperationException">Queue is empty.</exception>
        public T Dequeue()
        {
            if (_count == 0)
            {
                throw new InvalidOperationException(Strings.QueueIsEmpty);
            }

            var result = Linx.Clear(ref _buffer[_offset]);

            if (--_count == 0)
            {
                _offset = 0;
                if (_buffer.Length > _initialCapacity)
                {
                    _buffer = null;
                }
            }
            else
            {
                if (++_offset == _buffer.Length)
                {
                    _offset = 0;
                }
            }
            return(result);
        }
Пример #2
0
            protected TQueue DequeueOne()
            {
                if (IsEmpty)
                {
                    throw new InvalidOperationException(Strings.QueueIsEmpty);
                }

                var result = Linx.Clear(ref _buffer[_offset++]);

                if (--_count == 0)
                {
                    _offset = 0;
                    if (_buffer.Length < _initialCapacity)
                    {
                        _buffer = null;
                    }
                }
                else if (_offset == _buffer.Length)
                {
                    _offset = 0;
                }
                return(result);
            }