Go to the documentation of this file.
19 #ifndef __TPIE_INTERNAL_QUEUE_H__
20 #define __TPIE_INTERNAL_QUEUE_H__
44 size_t m_first, m_last;
81 const T &
back()
const {
return m_elements[(m_last-1) % m_elements.
size()];}
88 inline void push(T val){m_elements[m_last++ % m_elements.
size()] = val;}
93 inline void pop(){++m_first;}
99 inline bool empty()
const {
return m_first == m_last;}
105 inline bool full()
const {
return m_last - m_first == m_elements.
size();}
111 inline size_t size()
const {
return m_last - m_first;}
118 inline void clear(){m_first = m_last =0;}
122 #endif //__TPIE_INTERNAL_QUEUE_H__
Base class of data structures with linear memory usage.
const T & front() const
Return the item that has been in the queue for the longest time.
const T & back() const
Return the last item pushed to the queue.
bool full() const
Check if the queue is empty.
A generic internal circular queue.
size_t size() const
Return the number of elements in the queue.
void push(T val)
Add an element to the front of the queue.
static constexpr double memory_overhead() noexcept
Return the memory overhead of the structure.
static double memory_overhead()
Return the memory overhead of the structure.
void pop()
Remove an element from the back of the queue.
void clear()
Clear the queue of all elements.
#define tp_assert(condition, message)
bool empty() const
Check if the queue is empty.
static constexpr double memory_coefficient() noexcept
Return the memory coefficient of the structure.
void resize(size_t size, const T &elm)
Change the size of the array.
internal_queue(size_t size=0)
Construct a queue.
void resize(size_t size=0)
Resize the queue; all data is lost.
static double memory_coefficient()
Return the memory coefficient of the structure.
size_type size() const
Return the size of the array.