#include <BoundedPriorityQueue.h>
Inheritance diagram for oasys::BoundedPriorityQueue< T, TSize, TCompare >:
The default capacity is object size, but this can be overridden by supplying a TSize function pattern to read a different capacity from the T object.
Elements are sorted according to the priority provided by TCompare, which defaults to using the < operator, if the object defines one. This too can be overridden by supplying a comparator that detects a different priority from the T object.
Member function current() returns the current capacity. The maximum capacity is set by template variable, but can be updated by passing the new value to the constructor or set_max() method.
Bounds are enforced by the constructors and by push(). When a push() operation causes the BoundedPriorityQueue to exceed its maximum capacity, elements of least priority are dropped (by calling pop_back() on the underlying container) until the bound is no longer violated.
Other than the above exceptions, the default behavior is that of priority_queue
Definition at line 53 of file BoundedPriorityQueue.h.
Public Types | |
typedef std::vector< T > | Sequence |
typedef std::priority_queue< T, Sequence, TCompare > | PriorityQueue |
Public Member Functions | |
BoundedPriorityQueue (u_int max_size) | |
Default constructor. | |
BoundedPriorityQueue (const TCompare &comp, u_int max_size) | |
Alternate constructor. | |
void | push (const T &obj) |
Utilize priority_queue's default behavior, then update bounds tracking with new entry's TSize(), then enforce_bound. | |
void | pop () |
Decrement bounds tracking by this entry's TSize(), then utilize priority_queue's default pop() behavior. | |
u_int | current () const |
Report current bound status. | |
u_int | max () const |
Report maximum bound allowed. | |
void | set_max (u_int max_size) |
Update to new maximum bound. | |
Protected Types | |
typedef Sequence::const_iterator | const_iterator |
typedef Sequence::iterator | iterator |
Protected Member Functions | |
const Sequence & | container () const |
void | init () |
Initialize bounds tracking, then enforce_bound. | |
void | erase_member (iterator pos) |
Create a stub for derived classes to impose other policy upon object removal. | |
void | enforce_bound () |
Drop lowest priority elements until maximum bounds is no longer exceeded. | |
Protected Attributes | |
u_int | cur_size_ |
Current bound status. | |
u_int | max_size_ |
Maximum bound allowed. |
typedef std::vector<T> oasys::BoundedPriorityQueue< T, TSize, TCompare >::Sequence |
Definition at line 59 of file BoundedPriorityQueue.h.
typedef std::priority_queue<T,Sequence,TCompare> oasys::BoundedPriorityQueue< T, TSize, TCompare >::PriorityQueue |
Definition at line 60 of file BoundedPriorityQueue.h.
typedef Sequence::const_iterator oasys::BoundedPriorityQueue< T, TSize, TCompare >::const_iterator [protected] |
Definition at line 141 of file BoundedPriorityQueue.h.
typedef Sequence::iterator oasys::BoundedPriorityQueue< T, TSize, TCompare >::iterator [protected] |
Definition at line 142 of file BoundedPriorityQueue.h.
oasys::BoundedPriorityQueue< T, TSize, TCompare >::BoundedPriorityQueue | ( | u_int | max_size | ) | [inline] |
Default constructor.
max | defaults to template parameter, max_size |
Definition at line 66 of file BoundedPriorityQueue.h.
oasys::BoundedPriorityQueue< T, TSize, TCompare >::BoundedPriorityQueue | ( | const TCompare & | comp, | |
u_int | max_size | |||
) | [inline] |
Alternate constructor.
comp | comparator object | |
max | defaults to template parametr, max_size |
Definition at line 79 of file BoundedPriorityQueue.h.
void oasys::BoundedPriorityQueue< T, TSize, TCompare >::push | ( | const T & | obj | ) | [inline] |
Utilize priority_queue's default behavior, then update bounds tracking with new entry's TSize(), then enforce_bound.
Definition at line 91 of file BoundedPriorityQueue.h.
Referenced by dtn::ProphetBundleQueue::push().
void oasys::BoundedPriorityQueue< T, TSize, TCompare >::pop | ( | ) | [inline] |
Decrement bounds tracking by this entry's TSize(), then utilize priority_queue's default pop() behavior.
Reimplemented in dtn::ProphetBundleQueue.
Definition at line 102 of file BoundedPriorityQueue.h.
u_int oasys::BoundedPriorityQueue< T, TSize, TCompare >::current | ( | ) | const [inline] |
u_int oasys::BoundedPriorityQueue< T, TSize, TCompare >::max | ( | ) | const [inline] |
void oasys::BoundedPriorityQueue< T, TSize, TCompare >::set_max | ( | u_int | max_size | ) | [inline] |
Update to new maximum bound.
Definition at line 127 of file BoundedPriorityQueue.h.
Referenced by dtn::ProphetController::handle_max_usage_change().
const Sequence& oasys::BoundedPriorityQueue< T, TSize, TCompare >::container | ( | ) | const [inline, protected] |
Definition at line 136 of file BoundedPriorityQueue.h.
void oasys::BoundedPriorityQueue< T, TSize, TCompare >::init | ( | ) | [inline, protected] |
Initialize bounds tracking, then enforce_bound.
Definition at line 147 of file BoundedPriorityQueue.h.
Referenced by oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::BoundedPriorityQueue().
void oasys::BoundedPriorityQueue< T, TSize, TCompare >::erase_member | ( | iterator | pos | ) | [inline, protected] |
Create a stub for derived classes to impose other policy upon object removal.
Definition at line 159 of file BoundedPriorityQueue.h.
Referenced by oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::enforce_bound(), and dtn::ProphetBundleQueue::erase_member().
void oasys::BoundedPriorityQueue< T, TSize, TCompare >::enforce_bound | ( | ) | [inline, protected] |
Drop lowest priority elements until maximum bounds is no longer exceeded.
Reimplemented in dtn::ProphetBundleQueue.
Definition at line 168 of file BoundedPriorityQueue.h.
Referenced by dtn::ProphetBundleQueue::enforce_bound(), oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::init(), oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::push(), and oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::set_max().
u_int oasys::BoundedPriorityQueue< T, TSize, TCompare >::cur_size_ [protected] |
Current bound status.
Definition at line 187 of file BoundedPriorityQueue.h.
Referenced by oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::current(), dtn::ProphetBundleQueue::enforce_bound(), oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::enforce_bound(), oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::init(), oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::pop(), and oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::push().
u_int oasys::BoundedPriorityQueue< T, TSize, TCompare >::max_size_ [protected] |
Maximum bound allowed.
Definition at line 188 of file BoundedPriorityQueue.h.
Referenced by dtn::ProphetBundleQueue::enforce_bound(), oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::enforce_bound(), oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::max(), and oasys::BoundedPriorityQueue< dtn::Bundle *, dtn::BundleSz, dtn::QueueComp >::set_max().