37 Queue(
size_t sz) : data(sz), tail(0), head(0){}
42 tail = (tail + 1) % data.size();
44 if(tail == head) expand();
52 head = (head + 1) % data.size();
63 return tail >= head ? tail - head : data.size() - (head - tail);
74 size_t oldsz = data.size();
75 data.resize(oldsz * 2);
77 for(
size_t i = 0; i < oldsz; ++i){
78 data[oldsz + i] = std::move(data[(head + i) % oldsz]);
Simple queue class built on a std::vector.
Definition: nrg_queue.h:34
void push(const T &t)
Push t onto the back of the queue.
Definition: nrg_queue.h:40
bool empty()
Returns true if the queue is empty.
Definition: nrg_queue.h:67
T pop(void)
Remove the head of the queue and return it, don't call this if the queue is empty or all hell will br...
Definition: nrg_queue.h:48
size_t size()
Returns the size of the queue.
Definition: nrg_queue.h:62
Common defines and includes used by all the other nrg header files.
void clear()
Clears the queue.
Definition: nrg_queue.h:57
Queue(size_t sz)
Construct a Queue with initial size sz.
Definition: nrg_queue.h:37