39 Queue() : buf(1), first(0), end(0) {}
41 void clear (
bool dealloc =
false) { buf.
clear(dealloc); buf.
growTo(1); first = end = 0; }
42 int size ()
const {
return (end >= first) ? end -
first : end - first + buf.
size(); }
44 const T&
operator [] (
int index)
const { assert(index >= 0); assert(index <
size());
return buf[(first + index) % buf.
size()]; }
45 T&
operator [] (
int index) { assert(index >= 0); assert(index <
size());
return buf[(first + index) % buf.
size()]; }
47 T
peek ()
const { assert(first != end);
return buf[
first]; }
48 void pop () { assert(first != end); first++;
if (first == buf.
size()) first = 0; }
51 if (end == buf.
size()) end = 0;
55 **/printf(
"queue alloc: %d elems (%.1f MB)\n", tmp.
size(), tmp.
size() *
sizeof(T) / 1000000.0);
58 for (
int j = first; j < buf.
size(); j++) tmp[i++] = buf[j];
59 for (
int j = 0 ; j <
end ; j++) tmp[i++] = buf[j];
const T & operator[](int index) const
void clear(bool dealloc=false)
void moveTo(vec< T > &dest)
void clear(bool dealloc=false)