BoundedPriorityDeque
A lightweight, performant bounded priority deque with wide
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BoundedPriorityDequeKeyed< K, V, Comparator > Class Template Reference

Lightweight custom key comparator priority dequeue. More...

#include <BoundedPriorityDeque.hpp>

Inheritance diagram for BoundedPriorityDequeKeyed< K, V, Comparator >:
BoundedPriorityDequeBase< K, V >

Public Member Functions

 BoundedPriorityDequeKeyed (unsigned int capacity=0, Comparator comp=Comparator())
 
- Public Member Functions inherited from BoundedPriorityDequeBase< K, V >
 BoundedPriorityDequeBase (size_t capacity=0)
 Primary constructor with default bounding capacity of zero.
 
BoundingPair< K, V > top () const
 Get the highest-priority element.
 
BoundingPair< K, V > bottom () const
 Get the lowest-priority element.
 
topK () const
 Get the key from the highest-priority element.
 
bottomK () const
 Get the key from the lowest-priority element.
 
void emplace (K key, const V &value)
 constructs a BoundingPair<K, V> element and inserts it.
 
void push (const BoundingPair< K, V > &element)
 Inserts an element into the vector.
 
BoundingPair< K, V > operator[] (size_t offsetTop) const
 random accessor relative to the top of the deque.
 
BoundingPair< K, V > pop ()
 remove the highest-priority element.
 
BoundingPair< K, V > popBottom ()
 remove the lowest-priority element.
 
void operator+= (const BoundedPriorityDequeBase< K, V > &rhs)
 Merges another BoundedPriorityDeque instance into the calling instance.
 
void clear ()
 clears and resets the data structure.
 
size_t size () const
 
size_t capacity () const
 
bool empty () const
 
bool full () const
 
void resize (size_t k)
 Sets the capacity and restores clean state.
 

Protected Member Functions

bool compare (K a, K b) const override
 
- Protected Member Functions inherited from BoundedPriorityDequeBase< K, V >
size_t nextIndex (size_t current) const
 Provides fast access to the next index of a given insertion position.
 
size_t prevIndex (size_t current) const
 Provides fast access to the previous index of a given insertion position.
 
size_t binarySearch (const BoundingPair< K, V > &target) const
 Efficiently locates the optimal insertion index.
 
void insert (const BoundingPair< K, V > &element)
 Inserts an element into the _buffer.
 
void _popTop ()
 Internal method with no return val.
 
void _popBottom ()
 Internal method with no return val.
 

Protected Attributes

Comparator comparator
 
- Protected Attributes inherited from BoundedPriorityDequeBase< K, V >
std::vector< BoundingPair< K, V > > _buffer
 
size_t _k
 
size_t _size = 0
 
size_t _head = 0
 
size_t _tail = 0
 

Detailed Description

template<typename K, typename V, typename Comparator = std::less<K>>
class BoundedPriorityDequeKeyed< K, V, Comparator >

Lightweight custom key comparator priority dequeue.

This class provides a lightweight custom-comparator implement of the base class. This derived class allows for non-standard or non-arithmetic key types via a custom-comparator template argument. The custom-comparator should be in the form of a function<bool(K a, K b)> comparator which returns true if 'a' has a higher-priority than 'b'.

Template Parameters
KTemplate-comparator compatible key Type.
VType of the value.

Member Function Documentation

◆ compare()

template<typename K , typename V , typename Comparator = std::less<K>>
bool BoundedPriorityDequeKeyed< K, V, Comparator >::compare ( a,
b 
) const
inlineoverrideprotectedvirtual

Compares two keys.

Parameters
aThe first key.
bThe second key.
Returns
True if a is considered less than b in a min-oriented deque, or more in a max-oriented deque.

Implements BoundedPriorityDequeBase< K, V >.


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