MySQL 8.3.0
Source Code Documentation
circular_buffer_queue< Element_type > Class Template Reference

The class defines a type of queue with a predefined max capacity that is implemented using the circular memory buffer. More...

#include <rpl_rli_pdb.h>

Public Member Functions

 circular_buffer_queue (size_t max)
 
 circular_buffer_queue ()
 
 ~circular_buffer_queue ()=default
 
bool de_queue (Element_type *item)
 Content of the being dequeued item is copied to the arg-pointer location. More...
 
bool de_tail (Element_type *item)
 Similar to de_queue but extracting happens from the tail side. More...
 
size_t en_queue (Element_type *item)
 return the index where the arg item locates or an error encoded as a value circular_buffer_queue::error_result. More...
 
Element_type * head_queue ()
 return the value of data member of the head of the queue. More...
 
bool in (size_t i)
 
size_t get_length () const
 
bool empty () const
 
bool full () const
 

Public Attributes

Prealloced_array< Element_type, 1 > m_Q
 
size_t capacity
 The capacity and maximum length of the queue in terms of element. More...
 
size_t avail
 Its value modulo capacity is index of the element where the next element will be enqueued. More...
 
size_t entry
 The head index of the queue. More...
 
std::atomic< size_t > len
 Actual length. More...
 
bool inited_queue
 

Static Public Attributes

static constexpr size_t error_result = std::numeric_limits<size_t>::max()
 

Detailed Description

template<typename Element_type>
class circular_buffer_queue< Element_type >

The class defines a type of queue with a predefined max capacity that is implemented using the circular memory buffer.

That is items of the queue are accessed as indexed elements of the array buffer in a way that when the index value reaches a max value it wraps around to point to the first buffer element.

Constructor & Destructor Documentation

◆ circular_buffer_queue() [1/2]

template<typename Element_type >
circular_buffer_queue< Element_type >::circular_buffer_queue ( size_t  max)
inline

◆ circular_buffer_queue() [2/2]

template<typename Element_type >
circular_buffer_queue< Element_type >::circular_buffer_queue ( )
inline

◆ ~circular_buffer_queue()

template<typename Element_type >
circular_buffer_queue< Element_type >::~circular_buffer_queue ( )
default

Member Function Documentation

◆ de_queue()

template<typename Element_type >
bool circular_buffer_queue< Element_type >::de_queue ( Element_type *  item)

Content of the being dequeued item is copied to the arg-pointer location.

Dequeue from head.

Parameters
[out]itemA pointer to the being dequeued item.
Returns
true if an element was returned, false if the queue was empty.

◆ de_tail()

template<typename Element_type >
bool circular_buffer_queue< Element_type >::de_tail ( Element_type *  item)

Similar to de_queue but extracting happens from the tail side.

Parameters
[out]itemA pointer to the being dequeued item.
Returns
true if an element was returned, false if the queue was empty.

◆ empty()

template<typename Element_type >
bool circular_buffer_queue< Element_type >::empty ( ) const
inline

◆ en_queue()

template<typename Element_type >
size_t circular_buffer_queue< Element_type >::en_queue ( Element_type *  item)

return the index where the arg item locates or an error encoded as a value circular_buffer_queue::error_result.

Returns
the index where the arg item has been located or an error encoded as a value circular_buffer_queue::error_result.

◆ full()

template<typename Element_type >
bool circular_buffer_queue< Element_type >::full ( ) const
inline

◆ get_length()

template<typename Element_type >
size_t circular_buffer_queue< Element_type >::get_length ( ) const
inline

◆ head_queue()

template<typename Element_type >
Element_type * circular_buffer_queue< Element_type >::head_queue ( )
inline

return the value of data member of the head of the queue.

◆ in()

template<typename Element_type >
bool circular_buffer_queue< Element_type >::in ( size_t  i)
inline

Member Data Documentation

◆ avail

template<typename Element_type >
size_t circular_buffer_queue< Element_type >::avail

Its value modulo capacity is index of the element where the next element will be enqueued.

It's entry+length. It may be bigger than capacity, but will be smaller than 2*capacity.

◆ capacity

template<typename Element_type >
size_t circular_buffer_queue< Element_type >::capacity

The capacity and maximum length of the queue in terms of element.

◆ entry

template<typename Element_type >
size_t circular_buffer_queue< Element_type >::entry

The head index of the queue.

It is an index of next element that will be dequeued. It is less than capacity, so it is an actual index (in contrast to avail), don't need to be calculated modulo capacity.

◆ error_result

template<typename Element_type >
constexpr size_t circular_buffer_queue< Element_type >::error_result = std::numeric_limits<size_t>::max()
staticconstexpr

◆ inited_queue

template<typename Element_type >
bool circular_buffer_queue< Element_type >::inited_queue

◆ len

template<typename Element_type >
std::atomic<size_t> circular_buffer_queue< Element_type >::len

Actual length.

It can be read while not protected by any mutex.

◆ m_Q

template<typename Element_type >
Prealloced_array<Element_type, 1> circular_buffer_queue< Element_type >::m_Q

The documentation for this class was generated from the following file: