Ponca  e26a0e88a45818354616c1a7180bcd203aecad3c
Point Cloud Analysis library
Loading...
Searching...
No Matches
Ponca::limited_priority_queue< T, CompareT > Class Template Reference

The limited_priority_queue class is similar to std::priority_queue but has a limited capacity and handles the comparison differently. More...

#include <limitedPriorityQueue.h>

+ Inheritance diagram for Ponca::limited_priority_queue< T, CompareT >:
+ Collaboration diagram for Ponca::limited_priority_queue< T, CompareT >:

Public Types

using value_type = T
 
using container_type = std::vector< T >
 
using compare = CompareT
 
using iterator = typename container_type::iterator
 
using const_iterator = typename container_type::const_iterator
 
using this_type = limited_priority_queue< T, CompareT >
 

Public Member Functions

 limited_priority_queue (const this_type &other)
 
 limited_priority_queue (int capacity)
 
template<class InputIt >
 limited_priority_queue (int capacity, InputIt first, InputIt last)
 
limited_priority_queueoperator= (const this_type &other)
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cend () const
 
const T & top () const
 
const T & bottom () const
 
T & top ()
 
T & bottom ()
 
bool empty () const
 
bool full () const
 
size_t size () const
 
size_t capacity () const
 
bool push (const T &value)
 
bool push (T &&value)
 
void pop ()
 
void reserve (int capacity)
 
void clear ()
 
const container_type & container () const
 

Protected Attributes

container_type m_c
 
compare m_comp
 
size_t m_size {0}
 

Detailed Description

template<class T, class CompareT = std::less<T>>
class Ponca::limited_priority_queue< T, CompareT >

The limited_priority_queue class is similar to std::priority_queue but has a limited capacity and handles the comparison differently.

In case the capacity is reached, the container is full and push() do not insert a new element if its priority is lower than the current minimal one.

The comparison predicate must return true is the first argument has priority on the second one.

The element with the highest priority is the last one that is pop out, but is the first one that is iterated through.

Example 1: Using std::less as comparison predicate, we have the following situation:

full()      = false
empty()     = false
capacity()  = 6
size()      = 4
top()       = 1
bottom()    = 9

pop() removes the value 9
push(4) adds the value 4

begin            end
  v               v
+---+---+---+---+---+---+
| 1 | 3 | 8 | 9 |   |   |
+---+---+---+---+---+---+
  ^           ^
 top        bottom

Example 2: Using std::greater as comparison predicate, we have the following situation:

full()      = true
empty()     = false
capacity()  = 6
size()      = 6
top()       = 9
bottom()    = 2

begin                    end
  v                       v
+---+---+---+---+---+---+
| 9 | 8 | 6 | 4 | 3 | 2 |
+---+---+---+---+---+---+
  ^                   ^
 top                bottom

pop() removes the value 2
push(5) adds the value 5 and remove the value 2
push(0) do nothing

Definition at line 76 of file limitedPriorityQueue.h.

Member Typedef Documentation

◆ compare

template<class T , class CompareT = std::less<T>>
using Ponca::limited_priority_queue< T, CompareT >::compare = CompareT

Definition at line 81 of file limitedPriorityQueue.h.

◆ const_iterator

template<class T , class CompareT = std::less<T>>
using Ponca::limited_priority_queue< T, CompareT >::const_iterator = typename container_type::const_iterator

Definition at line 83 of file limitedPriorityQueue.h.

◆ container_type

template<class T , class CompareT = std::less<T>>
using Ponca::limited_priority_queue< T, CompareT >::container_type = std::vector<T>

Definition at line 80 of file limitedPriorityQueue.h.

◆ iterator

template<class T , class CompareT = std::less<T>>
using Ponca::limited_priority_queue< T, CompareT >::iterator = typename container_type::iterator

Definition at line 82 of file limitedPriorityQueue.h.

◆ this_type

template<class T , class CompareT = std::less<T>>
using Ponca::limited_priority_queue< T, CompareT >::this_type = limited_priority_queue<T,CompareT>

Definition at line 84 of file limitedPriorityQueue.h.

◆ value_type

template<class T , class CompareT = std::less<T>>
using Ponca::limited_priority_queue< T, CompareT >::value_type = T

Definition at line 79 of file limitedPriorityQueue.h.

Constructor & Destructor Documentation

◆ limited_priority_queue() [1/4]

template<class T , class Cmp >
Ponca::limited_priority_queue< T, Cmp >::limited_priority_queue
inline

Definition at line 152 of file limitedPriorityQueue.h.

◆ limited_priority_queue() [2/4]

template<class T , class Cmp >
Ponca::limited_priority_queue< T, Cmp >::limited_priority_queue ( const this_type other)
inline

Definition at line 161 of file limitedPriorityQueue.h.

◆ limited_priority_queue() [3/4]

template<class T , class Cmp >
Ponca::limited_priority_queue< T, Cmp >::limited_priority_queue ( int  capacity)
inlineexplicit

Definition at line 169 of file limitedPriorityQueue.h.

◆ limited_priority_queue() [4/4]

template<class T , class Cmp >
template<class InputIt >
Ponca::limited_priority_queue< T, Cmp >::limited_priority_queue ( int  capacity,
InputIt  first,
InputIt  last 
)
inline

Definition at line 178 of file limitedPriorityQueue.h.

◆ ~limited_priority_queue()

template<class T , class Cmp >
Ponca::limited_priority_queue< T, Cmp >::~limited_priority_queue
inline

Definition at line 190 of file limitedPriorityQueue.h.

Member Function Documentation

◆ begin() [1/2]

template<class T , class Cmp >
limited_priority_queue< T, Cmp >::iterator Ponca::limited_priority_queue< T, Cmp >::begin
inline

Definition at line 206 of file limitedPriorityQueue.h.

◆ begin() [2/2]

template<class T , class Cmp >
limited_priority_queue< T, Cmp >::const_iterator Ponca::limited_priority_queue< T, Cmp >::begin
inline

Definition at line 212 of file limitedPriorityQueue.h.

◆ bottom() [1/2]

template<class T , class Cmp >
T & Ponca::limited_priority_queue< T, Cmp >::bottom
inline

Definition at line 262 of file limitedPriorityQueue.h.

◆ bottom() [2/2]

template<class T , class Cmp >
const T & Ponca::limited_priority_queue< T, Cmp >::bottom
inline

Definition at line 250 of file limitedPriorityQueue.h.

◆ capacity()

template<class T , class Cmp >
size_t Ponca::limited_priority_queue< T, Cmp >::capacity
inline

Definition at line 288 of file limitedPriorityQueue.h.

◆ cbegin()

template<class T , class Cmp >
limited_priority_queue< T, Cmp >::const_iterator Ponca::limited_priority_queue< T, Cmp >::cbegin
inline

Definition at line 218 of file limitedPriorityQueue.h.

◆ cend()

template<class T , class Cmp >
limited_priority_queue< T, Cmp >::const_iterator Ponca::limited_priority_queue< T, Cmp >::cend
inline

Definition at line 236 of file limitedPriorityQueue.h.

◆ clear()

template<class T , class Cmp >
void Ponca::limited_priority_queue< T, Cmp >::clear
inline

Definition at line 398 of file limitedPriorityQueue.h.

◆ container()

template<class T , class Cmp >
const limited_priority_queue< T, Cmp >::container_type & Ponca::limited_priority_queue< T, Cmp >::container
inline

Definition at line 406 of file limitedPriorityQueue.h.

◆ empty()

template<class T , class Cmp >
bool Ponca::limited_priority_queue< T, Cmp >::empty
inline

Definition at line 270 of file limitedPriorityQueue.h.

◆ end() [1/2]

template<class T , class Cmp >
limited_priority_queue< T, Cmp >::iterator Ponca::limited_priority_queue< T, Cmp >::end
inline

Definition at line 224 of file limitedPriorityQueue.h.

◆ end() [2/2]

template<class T , class Cmp >
limited_priority_queue< T, Cmp >::const_iterator Ponca::limited_priority_queue< T, Cmp >::end
inline

Definition at line 230 of file limitedPriorityQueue.h.

◆ full()

template<class T , class Cmp >
bool Ponca::limited_priority_queue< T, Cmp >::full
inline

Definition at line 276 of file limitedPriorityQueue.h.

◆ operator=()

template<class T , class Cmp >
limited_priority_queue< T, Cmp > & Ponca::limited_priority_queue< T, Cmp >::operator= ( const this_type other)
inline

Definition at line 195 of file limitedPriorityQueue.h.

◆ pop()

template<class T , class Cmp >
void Ponca::limited_priority_queue< T, Cmp >::pop
inline

Definition at line 382 of file limitedPriorityQueue.h.

◆ push() [1/2]

template<class T , class Cmp >
bool Ponca::limited_priority_queue< T, Cmp >::push ( const T &  value)
inline

Definition at line 296 of file limitedPriorityQueue.h.

◆ push() [2/2]

template<class T , class Cmp >
bool Ponca::limited_priority_queue< T, Cmp >::push ( T &&  value)
inline

Definition at line 339 of file limitedPriorityQueue.h.

◆ reserve()

template<class T , class Cmp >
void Ponca::limited_priority_queue< T, Cmp >::reserve ( int  capacity)
inline

Definition at line 388 of file limitedPriorityQueue.h.

◆ size()

template<class T , class Cmp >
size_t Ponca::limited_priority_queue< T, Cmp >::size
inline

Definition at line 282 of file limitedPriorityQueue.h.

◆ top() [1/2]

template<class T , class Cmp >
T & Ponca::limited_priority_queue< T, Cmp >::top
inline

Definition at line 256 of file limitedPriorityQueue.h.

◆ top() [2/2]

template<class T , class Cmp >
const T & Ponca::limited_priority_queue< T, Cmp >::top
inline

Definition at line 244 of file limitedPriorityQueue.h.

Member Data Documentation

◆ m_c

template<class T , class CompareT = std::less<T>>
container_type Ponca::limited_priority_queue< T, CompareT >::m_c
protected

Definition at line 139 of file limitedPriorityQueue.h.

◆ m_comp

template<class T , class CompareT = std::less<T>>
compare Ponca::limited_priority_queue< T, CompareT >::m_comp
protected

Definition at line 140 of file limitedPriorityQueue.h.

◆ m_size

template<class T , class CompareT = std::less<T>>
size_t Ponca::limited_priority_queue< T, CompareT >::m_size {0}
protected

Definition at line 141 of file limitedPriorityQueue.h.