38 const T &
operator[](
const size_t offset)
const;
53 const T &
front(
void)
const;
68 const T &
back(
void)
const;
74 bool empty(
void)
const;
77 bool full(
void)
const;
80 size_t size(
void)
const;
95 std::vector<T> _container;
108 template <
typename T>
111 _backIndex(capacity-1),
115 assert(capacity > 0);
118 template <
typename T>
121 return _container[(_frontIndex + offset) % _container.size()];
124 template <
typename T>
127 return _container[(_frontIndex + offset) % _container.size()];
130 template <
typename T>
133 assert(not this->full());
134 _frontIndex = size_t(_frontIndex + _container.size() - 1) % _container.size();
135 _container[_frontIndex] = elem;
139 template <
typename T>
142 assert(not this->full());
143 _frontIndex = size_t(_frontIndex + _container.size() - 1) % _container.size();
144 _container[_frontIndex] = elem;
148 template <
typename T>
151 assert(not this->empty());
152 assert(_frontIndex < _container.size());
153 T old; std::swap(_container[_frontIndex], old);
154 _frontIndex = size_t(_frontIndex + 1) % _container.size();
158 template <
typename T>
161 assert(not this->empty());
162 assert(_frontIndex < _container.size());
163 return _container[_frontIndex];
166 template <
typename T>
169 assert(not this->empty());
170 assert(_frontIndex < _container.size());
171 return _container[_frontIndex];
174 template <
typename T>
177 assert(not this->full());
178 _backIndex = size_t(_backIndex + 1) % _container.size();
179 _container[_backIndex] = elem;
183 template <
typename T>
186 assert(not this->full());
187 _backIndex = size_t(_backIndex + 1) % _container.size();
188 _container[_backIndex] = elem;
192 template <
typename T>
195 assert(not this->empty());
196 assert(_backIndex < _container.size());
197 T old; std::swap(_container[_backIndex], old);
198 _backIndex = size_t(_backIndex + _container.size() - 1) % _container.size();
202 template <
typename T>
205 assert(not this->empty());
206 assert(_backIndex < _container.size());
207 return _container[_backIndex];
210 template <
typename T>
213 assert(not this->empty());
214 assert(_backIndex < _container.size());
215 return _container[_backIndex];
218 template <
typename T>
221 return _numElements == 0;
224 template <
typename T>
227 return _numElements == _container.size();
230 template <
typename T>
236 template <
typename T>
239 return _container.size();
242 template <
typename T>
245 if (_numElements > capacity)
return;
246 std::vector<T> _newContainer(capacity);
247 for (
size_t i = 0; i < _numElements; i++)
249 _newContainer[i] = _container[(_frontIndex+i) % _container.size()];
251 _container = _newContainer;
253 _backIndex = (_numElements + capacity - 1) % capacity;
256 template <
typename T>
259 while (not this->empty())
const T & operator[](const size_t offset) const
Get a const ref at, where front == 0, back == size() - 1.
Definition: RingDeque.hpp:119
size_t capacity(void) const
How many elements can be stored?
Definition: RingDeque.hpp:237
void pop_back(void)
Pop and element from the back of the queue.
Definition: RingDeque.hpp:193
size_t size(void) const
How many elements are in the deque.
Definition: RingDeque.hpp:231
bool empty(void) const
Is the deque empty? – no elements.
Definition: RingDeque.hpp:219
void set_capacity(const size_t capacity)
Set the deque capacity if too small.
Definition: RingDeque.hpp:243
void clear(void)
Empty the contents of this queue.
Definition: RingDeque.hpp:257
RingDeque(void)
Construct a new ring deque.
Definition: RingDeque.hpp:99
void pop_front(void)
Pop and element from the front of the queue.
Definition: RingDeque.hpp:149
Definition: RingDeque.hpp:28
const T & front(void) const
Get a const reference to the front element.
Definition: RingDeque.hpp:159
bool full(void) const
Is the deque full? – num elements == capacity.
Definition: RingDeque.hpp:225
const T & back(void) const
Get a const reference to the back element.
Definition: RingDeque.hpp:203
void push_back(const T &elem)
Push an element onto the back of the queue.
Definition: RingDeque.hpp:175
void push_front(const T &elem)
Push an element onto the front of the queue.
Definition: RingDeque.hpp:131