40 static const int TERMINAL = -1;
51 _rev(n, TERMINAL), _fwd(n, TERMINAL) { }
56 inline bool empty()
const {
return (_head == TERMINAL); }
60 _head = _tail = TERMINAL;
61 fill(_rev.begin(), _rev.end(), TERMINAL);
62 fill(_fwd.begin(), _fwd.end(), TERMINAL);
67 _rev.resize(n); _fwd.resize(n); clear();
71 inline int front()
const {
return _head; }
73 inline int back()
const {
return _tail; }
77 return (_rev[u] != TERMINAL);
82 if (is_queued(u))
return;
84 if (_tail == TERMINAL) {
85 _head = _tail = _fwd[u] = _rev[u] = u;
97 if (is_queued(u))
return;
99 if (_head == TERMINAL) {
100 _head = _tail = _fwd[u] = _rev[u] = u;
112 DRWN_ASSERT(_head != TERMINAL);
113 _rev[_head] = TERMINAL;
114 if (_head == _tail) {
115 _head = _tail = TERMINAL;
125 if (!is_queued(u))
return;
127 if (_head == _tail) {
128 _head = _tail = TERMINAL;
130 _fwd[_rev[u]] = _fwd[u];
131 _rev[_fwd[u]] = _rev[u];
132 if (_head == u) _head = _fwd[u];
133 if (_tail == u) _tail = _rev[u];
void push_front(int u)
add u to the front of the queue
Definition: drwnIndexQueue.h:96
void resize(size_t n)
clears and resizes the queue
Definition: drwnIndexQueue.h:66
void erase(int u)
remove u from the queue or do nothing if not in the queue
Definition: drwnIndexQueue.h:124
int front() const
return the element at the front of the queue (or -1 if empty)
Definition: drwnIndexQueue.h:71
int back() const
return the element at the back of the queue (or -1 if empty)
Definition: drwnIndexQueue.h:73
void clear()
clears the queue
Definition: drwnIndexQueue.h:59
bool empty() const
returns true if the queue is empty
Definition: drwnIndexQueue.h:56
drwnIndexQueue(size_t n)
constructor takes the maximum number of indexes
Definition: drwnIndexQueue.h:50
std::string toString(const T &v)
Templated function to make conversion from simple data types like int and double to strings easy for ...
Definition: drwnStrUtils.h:134
drwnIndexQueue()
default constructor of an empty queue
Definition: drwnIndexQueue.h:48
void pop_front()
remove the elelemt from the head of the queue
Definition: drwnIndexQueue.h:111
~drwnIndexQueue()
destructor
Definition: drwnIndexQueue.h:53
bool is_queued(int u) const
returns true if u is in the queue
Definition: drwnIndexQueue.h:76
Provides a queue datastructure on a fixed number of indexes. At most one copy of each index can appea...
Definition: drwnIndexQueue.h:38
void push_back(int u)
add u to the back of the queue
Definition: drwnIndexQueue.h:81