3#ifndef DUNE_FUNCTIONS_COMMON_RESERVEDDEQUE_HH
4#define DUNE_FUNCTIONS_COMMON_RESERVEDDEQUE_HH
13#include <initializer_list>
15#include <dune/common/genericiterator.hh>
17#ifdef CHECK_RESERVEDDEQUE
18#define CHECKSIZE(X) assert(X)
20#define CHECKSIZE(X) {}
43 template<
class T,
int n>
63 typedef Dune::GenericIterator<ReservedDeque, value_type>
iterator;
65 typedef Dune::GenericIterator<const ReservedDeque, const value_type>
const_iterator;
79 assert(l.size() <= n);
81 std::copy_n(l.begin(), size_, data_);
106 data_[size_++ % n] = t;
114 first_ = (first_+(n-1)) % n;
131 first_ = (++first_) % n;
159 return data_[(first_ + i) % n];
166 return data_[(first_ + i) % n];
173 return data_[first_];
180 return data_[first_];
187 return data_[(first_ + size_-1) % n];
194 return data_[(first_ + size_-1) % n];
230 for (
size_t i=0; i<v.
size(); i++)
#define CHECKSIZE(X)
Definition: reserveddeque.hh:20
Definition: polynomial.hh:10
A double-ended queue (deque) class with statically reserved memory.
Definition: reserveddeque.hh:45
void pop_front()
Erases the first element of the vector, O(1) time.
Definition: reserveddeque.hh:126
static constexpr size_type capacity()
Returns current capacity (allocated memory) of the vector.
Definition: reserveddeque.hh:214
void clear()
Erases all elements.
Definition: reserveddeque.hh:89
Dune::GenericIterator< ReservedDeque, value_type > iterator
Iterator used to iterate through a vector.
Definition: reserveddeque.hh:63
T value_type
The type of object, T, stored in the vector.
Definition: reserveddeque.hh:51
ReservedDeque()
Constructor.
Definition: reserveddeque.hh:72
bool empty() const
Returns true if vector has no elements.
Definition: reserveddeque.hh:208
const_reference back() const
Returns const reference to last element of vector.
Definition: reserveddeque.hh:191
friend std::ostream & operator<<(std::ostream &s, const ReservedDeque &v)
Send ReservedDeque to an output stream.
Definition: reserveddeque.hh:228
void push_front(const T &t)
Prepends an element to the begin of a deque if size<capacity, O(1) time.
Definition: reserveddeque.hh:110
reference operator[](size_type i)
Returns reference to the i'th element.
Definition: reserveddeque.hh:156
reference front()
Returns reference to first element of vector.
Definition: reserveddeque.hh:170
T * pointer
Pointer to T.
Definition: reserveddeque.hh:53
const_reference front() const
Returns const reference to first element of vector.
Definition: reserveddeque.hh:177
iterator end()
Returns an iterator pointing to the end of the vector.
Definition: reserveddeque.hh:146
reference back()
Returns reference to last element of vector.
Definition: reserveddeque.hh:184
void pop_back()
Erases the last element of the vector, O(1) time.
Definition: reserveddeque.hh:119
const T & const_reference
Const reference to T.
Definition: reserveddeque.hh:57
static constexpr size_type max_size()
Returns the maximum length of the vector.
Definition: reserveddeque.hh:220
std::ptrdiff_t difference_type
A signed integral type.
Definition: reserveddeque.hh:61
T & reference
Reference to T.
Definition: reserveddeque.hh:55
Dune::GenericIterator< const ReservedDeque, const value_type > const_iterator
Const iterator used to iterate through a vector.
Definition: reserveddeque.hh:65
size_type size() const
Returns number of elements in the vector.
Definition: reserveddeque.hh:202
const_iterator end() const
Returns a const_iterator pointing to the end of the vector.
Definition: reserveddeque.hh:151
void resize(size_t s)
Specifies a new size for the vector.
Definition: reserveddeque.hh:96
iterator begin()
Returns a iterator pointing to the beginning of the vector.
Definition: reserveddeque.hh:136
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the vector.
Definition: reserveddeque.hh:141
ReservedDeque(std::initializer_list< T > const &l)
Definition: reserveddeque.hh:77
size_t size_type
An unsigned integral type.
Definition: reserveddeque.hh:59
void push_back(const T &t)
Appends an element to the end of a vector, up to the maximum size n, O(1) time.
Definition: reserveddeque.hh:103