yat  0.21pre
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
theplu::yat::utility::PriorityQueue< T, Compare > Class Template Reference

Multi-thread safe priority queue. More...

#include <yat/utility/PriorityQueue.h>

Inheritance diagram for theplu::yat::utility::PriorityQueue< T, Compare >:
theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare >, T, std::multiset< T, Compare > >

Public Types

typedef std::multiset< T, Compare > ::value_type value_type
 Type of object stored.
 
typedef std::multiset< T, Compare > ::size_type size_type
 

Public Member Functions

 PriorityQueue (void)
 Create a PriorityQueue with no elements.
 
 PriorityQueue (const Compare &comp)
 Create a PriorityQueue with comp as Compare functor.
 
 PriorityQueue (const PriorityQueue &other)
 Copy constructor.
 
PriorityQueueoperator= (const PriorityQueue &lhs)
 assignment operator
 
size_t capacity (void)
 
void capacity (size_t c)
 change maximal number of element stored in container More...
 
void clear (void)
 clear queue More...
 
bool empty (void) const
 
void pop (T &value)
 access next element in queue More...
 
void push (const T &t)
 insert an element into container More...
 
void push (T &&t)
 insert an element into container More...
 
size_type size (void) const
 
bool try_pop (T &value)
 
bool try_push (T &value)
 
bool try_push (T &&value)
 

Protected Member Functions

void assign (const BasicQueue &other)
 

Protected Attributes

std::multiset< T, Compare > q_
 data
 

Friends

class detail::BasicQueue< PriorityQueue< T, Compare >, T, std::multiset< T, Compare > >
 

Detailed Description

template<typename T, class Compare = std::less<T>>
class theplu::yat::utility::PriorityQueue< T, Compare >

Multi-thread safe priority queue.

This class provides a multi-thread safe priority_queue. The PriorityQueue is typically shared by multiple threads such that some threads push elements and some pop elements. The PriorityQueue is a specifically designed so you can only access the greatest element similar tostd::priority_queue. The difference is that Queue is multi-thread safe, in other words, when one thread access the Queue, other threads are locked out from access so that only one thread touches the Queue at a time and its behaviour is well defined. In a single-thread application there is no point in using the class as std::queue should be prefereble.

Note
Copy constructor and assignment are available but they are not thread safe in the current implementation.
Since
New in yat 0.13

Member Typedef Documentation

◆ size_type

typedef std::multiset< T, Compare > ::size_type theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::size_type
inherited

An unsigned integral type.

See also
size(void)

Member Function Documentation

◆ assign()

void theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::assign ( const BasicQueue< PriorityQueue< T, Compare >, T, std::multiset< T, Compare > > &  other)
inlineprotectedinherited

assign other to this

◆ capacity() [1/2]

size_t theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::capacity ( void  )
inlineinherited
Returns
maximal number of element stored in container
Since
New in yat 0.19

◆ capacity() [2/2]

void theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::capacity ( size_t  c)
inlineinherited

change maximal number of element stored in container

Since
New in yat 0.19

◆ clear()

void theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::clear ( void  )
inlineinherited

clear queue

Since
new in yat 0.15

◆ empty()

bool theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::empty ( void  ) const
inlineinherited
Returns
true if container's size is zero

◆ pop()

void theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::pop ( T &  value)
inlineinherited

access next element in queue

Access the next element is queue. If container is empty, process is waiting until other process is inserting element into container.

◆ push() [1/2]

void theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::push ( const T &  t)
inlineinherited

insert an element into container

If size of queue is equal (or greater) to its capacity, the function is waiting until this is not the case.

◆ push() [2/2]

void theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::push ( T &&  t)
inlineinherited

insert an element into container

Since
New in yat 0.15

◆ size()

size_type theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::size ( void  ) const
inlineinherited
Returns
Number of elements stored in container

◆ try_pop()

bool theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::try_pop ( T &  value)
inlineinherited

If Queue is empty() do nothing and return false, else pop the element into value and return true

◆ try_push() [1/2]

bool theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::try_push ( T &  value)
inlineinherited

If Queue size is less than capacity push value and return true; otherwise return false

Since
New in yat 0.19

◆ try_push() [2/2]

bool theplu::yat::utility::detail::BasicQueue< PriorityQueue< T, Compare > , T, std::multiset< T, Compare > >::try_push ( T &&  value)
inlineinherited

If Queue size is less than capacity push value and return true; otherwise return false

Since
New in yat 0.19

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

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14