CppCommon  1.0.4.1
C++ Common Library
Classes | Public Types | Public Member Functions | Friends | List of all members
CppCommon::Queue< T > Class Template Reference

Intrusive queue container. More...

#include <queue.h>

Classes

struct  Node
 Queue node. More...
 

Public Types

typedef T value_type
 
typedef value_typereference
 
typedef const value_typeconst_reference
 
typedef value_typepointer
 
typedef const value_typeconst_pointer
 
typedef ptrdiff_t difference_type
 
typedef size_t size_type
 
typedef QueueIterator< T > iterator
 
typedef QueueConstIterator< T > const_iterator
 

Public Member Functions

 Queue () noexcept
 
template<class InputIterator >
 Queue (InputIterator first, InputIterator last) noexcept
 
 Queue (const Queue &) noexcept=default
 
 Queue (Queue &&) noexcept=default
 
 ~Queue () noexcept=default
 
Queueoperator= (const Queue &) noexcept=default
 
Queueoperator= (Queue &&) noexcept=default
 
 operator bool () const noexcept
 Check if the queue is not empty. More...
 
bool empty () const noexcept
 Is the queue empty? More...
 
size_t size () const noexcept
 Get the queue size. More...
 
T * front () noexcept
 Get the front queue item. More...
 
const T * front () const noexcept
 
T * back () noexcept
 Get the back queue item. More...
 
const T * back () const noexcept
 
iterator begin () noexcept
 Get the begin queue iterator. More...
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 Get the end queue iterator. More...
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
void push (T &item) noexcept
 Push a new item into the back of the queue. More...
 
T * pop () noexcept
 Pop the item from the front of the queue. More...
 
void reverse () noexcept
 Reverse the queue. More...
 
void clear () noexcept
 Clear the queue. More...
 
void swap (Queue &queue) noexcept
 Swap two instances. More...
 

Friends

template<typename U >
void swap (Queue< U > &queue1, Queue< U > &queue2) noexcept
 

Detailed Description

template<typename T>
class CppCommon::Queue< T >

Intrusive queue container.

Queue represents container with FIFO (first in - first out) stock algorithm. For example, you insert item A into queue. Then you insert item B into queue. There is an item A at the begin of the queue and there is an item B at the end of the queue. After removing item A, there will be an item B at the begin of the queue.

Front Insert here --->--Back
| |
+-----+ +-----+ +-----+ +-----+
| | Next | | Next | | Next | | Next
| 1 |-------->| 2 |-------->| 3 |-------->| 4 |--------> NULL
| | | | | | | |
+-----+ +-----+ +-----+ +-----+
|
+--->--- Remove from here

Not thread-safe.

Overview

Queue

In providing services in computer science, transport, and operations research a queue is a buffer where various entities such as data, objects, persons, or events are stored and waiting to be processed. The most well known operation of the queue is the First-In-First-Out (FIFO) queue process - In a FIFO queue, the first element in the queue will be the first one out; this is equivalent to the requirement that whenever an element is added, all elements that were added before have to be removed before the new element can be invoked.

There are two basic operations associated with a queue: enqueue and dequeue. Enqueue means adding a new item to the rear of the queue while dequeue refers to removing the front item from queue and returns it in item.

Theoretically, one characteristic of a queue is that it does not have a specific capacity. Regardless of how many elements are already contained, a new element can always be added. It can also be empty, at which point removing an element will be impossible until a new element has been added again.

A practical implementation of a queue of course does have some capacity limit, that depends on the concrete situation it is used in. For a data structure the executing computer will eventually run out of memory, thus limiting the queue size. Queue overflow results from trying to add an element onto a full queue and queue underflow happens when trying to remove an element from an empty queue.

Scheduling and buffering queues A queue is natural data structure for a system to serve the incoming requests. Most of the process scheduling or disk scheduling algorithms in operating systems use queues. Computer hardware like a processor or a network card also maintain buffers in the form of queues for incoming resource requests. A stack like data structure causes starvation of the first requests, and is not applicable in such cases. A mailbox or port to save messages to communicate between two users or processes in a system is essentially a queue like structure.

Search space exploration Like stacks, queues can be used to remember the search space that needs to be explored at one point of time in traversing algorithms. Breadth first search of a graph uses a queue to remember the nodes yet to be visited.

References

Taken from:
Stack from Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Queue

Examples
containers_queue.cpp.

Definition at line 103 of file queue.h.

Member Typedef Documentation

◆ const_iterator

template<typename T >
typedef QueueConstIterator<T> CppCommon::Queue< T >::const_iterator

Definition at line 115 of file queue.h.

◆ const_pointer

template<typename T >
typedef const value_type* CppCommon::Queue< T >::const_pointer

Definition at line 111 of file queue.h.

◆ const_reference

template<typename T >
typedef const value_type& CppCommon::Queue< T >::const_reference

Definition at line 109 of file queue.h.

◆ difference_type

template<typename T >
typedef ptrdiff_t CppCommon::Queue< T >::difference_type

Definition at line 112 of file queue.h.

◆ iterator

template<typename T >
typedef QueueIterator<T> CppCommon::Queue< T >::iterator

Definition at line 114 of file queue.h.

◆ pointer

template<typename T >
typedef value_type* CppCommon::Queue< T >::pointer

Definition at line 110 of file queue.h.

◆ reference

template<typename T >
typedef value_type& CppCommon::Queue< T >::reference

Definition at line 108 of file queue.h.

◆ size_type

template<typename T >
typedef size_t CppCommon::Queue< T >::size_type

Definition at line 113 of file queue.h.

◆ value_type

template<typename T >
typedef T CppCommon::Queue< T >::value_type

Definition at line 107 of file queue.h.

Constructor & Destructor Documentation

◆ Queue() [1/4]

template<typename T >
CppCommon::Queue< T >::Queue ( )
inlinenoexcept

Definition at line 125 of file queue.h.

◆ Queue() [2/4]

template<typename T >
template<class InputIterator >
CppCommon::Queue< T >::Queue ( InputIterator  first,
InputIterator  last 
)
inlinenoexcept

Definition at line 13 of file queue.inl.

◆ Queue() [3/4]

template<typename T >
CppCommon::Queue< T >::Queue ( const Queue< T > &  )
defaultnoexcept

◆ Queue() [4/4]

template<typename T >
CppCommon::Queue< T >::Queue ( Queue< T > &&  )
defaultnoexcept

◆ ~Queue()

template<typename T >
CppCommon::Queue< T >::~Queue ( )
defaultnoexcept

Member Function Documentation

◆ back() [1/2]

template<typename T >
const T* CppCommon::Queue< T >::back ( ) const
inlinenoexcept

Definition at line 149 of file queue.h.

◆ back() [2/2]

template<typename T >
T* CppCommon::Queue< T >::back ( )
inlinenoexcept

Get the back queue item.

Definition at line 148 of file queue.h.

◆ begin() [1/2]

template<typename T >
Queue< T >::const_iterator CppCommon::Queue< T >::begin
inlinenoexcept

Definition at line 26 of file queue.inl.

◆ begin() [2/2]

template<typename T >
Queue< T >::iterator CppCommon::Queue< T >::begin
inlinenoexcept

Get the begin queue iterator.

Definition at line 20 of file queue.inl.

◆ cbegin()

template<typename T >
Queue< T >::const_iterator CppCommon::Queue< T >::cbegin
inlinenoexcept

Definition at line 32 of file queue.inl.

◆ cend()

template<typename T >
Queue< T >::const_iterator CppCommon::Queue< T >::cend
inlinenoexcept

Definition at line 50 of file queue.inl.

◆ clear()

template<typename T >
void CppCommon::Queue< T >::clear
inlinenoexcept

Clear the queue.

Definition at line 101 of file queue.inl.

◆ empty()

template<typename T >
bool CppCommon::Queue< T >::empty ( ) const
inlinenoexcept

Is the queue empty?

Definition at line 139 of file queue.h.

◆ end() [1/2]

template<typename T >
Queue< T >::const_iterator CppCommon::Queue< T >::end
inlinenoexcept

Definition at line 44 of file queue.inl.

◆ end() [2/2]

template<typename T >
Queue< T >::iterator CppCommon::Queue< T >::end
inlinenoexcept

Get the end queue iterator.

Definition at line 38 of file queue.inl.

◆ front() [1/2]

template<typename T >
const T* CppCommon::Queue< T >::front ( ) const
inlinenoexcept

Definition at line 146 of file queue.h.

◆ front() [2/2]

template<typename T >
T* CppCommon::Queue< T >::front ( )
inlinenoexcept

Get the front queue item.

Definition at line 145 of file queue.h.

◆ operator bool()

template<typename T >
CppCommon::Queue< T >::operator bool ( ) const
inlineexplicitnoexcept

Check if the queue is not empty.

Definition at line 136 of file queue.h.

◆ operator=() [1/2]

template<typename T >
Queue& CppCommon::Queue< T >::operator= ( const Queue< T > &  )
defaultnoexcept

◆ operator=() [2/2]

template<typename T >
Queue& CppCommon::Queue< T >::operator= ( Queue< T > &&  )
defaultnoexcept

◆ pop()

template<typename T >
T * CppCommon::Queue< T >::pop
inlinenoexcept

Pop the item from the front of the queue.

Returns
The front item popped from the queue
Examples
containers_queue.cpp.

Definition at line 68 of file queue.inl.

◆ push()

template<typename T >
void CppCommon::Queue< T >::push ( T &  item)
inlinenoexcept

Push a new item into the back of the queue.

Parameters
item- Pushed item
Examples
containers_queue.cpp.

Definition at line 56 of file queue.inl.

◆ reverse()

template<typename T >
void CppCommon::Queue< T >::reverse
inlinenoexcept

Reverse the queue.

Definition at line 83 of file queue.inl.

◆ size()

template<typename T >
size_t CppCommon::Queue< T >::size ( ) const
inlinenoexcept

Get the queue size.

Definition at line 142 of file queue.h.

◆ swap()

template<typename T >
void CppCommon::Queue< T >::swap ( Queue< T > &  queue)
inlinenoexcept

Swap two instances.

Definition at line 109 of file queue.inl.

Friends And Related Function Documentation

◆ swap

template<typename T >
template<typename U >
void swap ( Queue< U > &  queue1,
Queue< U > &  queue2 
)
friend

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