MySQL 9.1.0
Source Code Documentation
Bounded_queue< Element_type, Key_type, Key_generator, Key_compare > Class Template Reference

A priority queue with a fixed, limited size. More...

#include <bounded_queue.h>

Public Types

typedef Priority_queue< Key_type, std::vector< Key_type, Malloc_allocator< Key_type > >, Key_compare > Queue_type
 
typedef Queue_type::allocator_type allocator_type
 

Public Member Functions

 Bounded_queue (size_t element_size=sizeof(Element_type), const allocator_type &alloc=allocator_type(PSI_NOT_INSTRUMENTED))
 
bool init (ha_rows max_elements, Key_generator *sort_param, Key_type *sort_keys)
 Initialize the queue. More...
 
template<class Opaque >
bool push (const Opaque &opaque)
 Pushes an element on the queue. More...
 
size_t num_elements () const
 The number of elements in the queue. More...
 

Private Attributes

Queue_type m_queue
 
Key_type * m_sort_keys
 
Key_generator * m_sort_param
 
size_t m_element_size
 

Detailed Description

template<typename Element_type, typename Key_type, typename Key_generator, typename Key_compare = std::less<Key_type>>
class Bounded_queue< Element_type, Key_type, Key_generator, Key_compare >

A priority queue with a fixed, limited size.

This is a wrapper on top of Priority_queue. It keeps the top-N elements which are inserted.

Elements of type Element_type are pushed into the queue. For each element, we call a user-supplied Key_generator::make_sortkey(), to generate a key of type Key_type for the element. Instances of Key_type are compared with the user-supplied Key_compare.

Pointers to the top-N elements are stored in the sort_keys array given to the init() function below. To access elements in sorted order, sort the array and access it sequentially.

Member Typedef Documentation

◆ allocator_type

template<typename Element_type , typename Key_type , typename Key_generator , typename Key_compare = std::less<Key_type>>
typedef Queue_type::allocator_type Bounded_queue< Element_type, Key_type, Key_generator, Key_compare >::allocator_type

◆ Queue_type

template<typename Element_type , typename Key_type , typename Key_generator , typename Key_compare = std::less<Key_type>>
typedef Priority_queue< Key_type, std::vector<Key_type, Malloc_allocator<Key_type> >, Key_compare> Bounded_queue< Element_type, Key_type, Key_generator, Key_compare >::Queue_type

Constructor & Destructor Documentation

◆ Bounded_queue()

template<typename Element_type , typename Key_type , typename Key_generator , typename Key_compare = std::less<Key_type>>
Bounded_queue< Element_type, Key_type, Key_generator, Key_compare >::Bounded_queue ( size_t  element_size = sizeof(Element_type),
const allocator_type alloc = allocator_type(PSI_NOT_INSTRUMENTED) 
)
inline

Member Function Documentation

◆ init()

template<typename Element_type , typename Key_type , typename Key_generator , typename Key_compare = std::less<Key_type>>
bool Bounded_queue< Element_type, Key_type, Key_generator, Key_compare >::init ( ha_rows  max_elements,
Key_generator *  sort_param,
Key_type *  sort_keys 
)
inline

Initialize the queue.

Parameters
max_elementsThe size of the queue.
sort_paramSort parameters. We call sort_param->make_sortkey() to generate keys for elements.
[in,out]sort_keysArray of keys to sort. Must be initialized by caller. Will be filled with pointers to the top-N elements.
Return values
falseOK, true Could not allocate memory.

We do not take ownership of any of the input pointer arguments.

◆ num_elements()

template<typename Element_type , typename Key_type , typename Key_generator , typename Key_compare = std::less<Key_type>>
size_t Bounded_queue< Element_type, Key_type, Key_generator, Key_compare >::num_elements ( ) const
inline

The number of elements in the queue.

◆ push()

template<typename Element_type , typename Key_type , typename Key_generator , typename Key_compare = std::less<Key_type>>
template<class Opaque >
bool Bounded_queue< Element_type, Key_type, Key_generator, Key_compare >::push ( const Opaque &  opaque)
inline

Pushes an element on the queue.

If the queue is already full, we discard one element. Calls m_sort_param::make_sortkey() to generate a key for the element.

Parameters
opaqueParameter to send on to make_sortkey().
Return values
falseOK, true error.

Member Data Documentation

◆ m_element_size

template<typename Element_type , typename Key_type , typename Key_generator , typename Key_compare = std::less<Key_type>>
size_t Bounded_queue< Element_type, Key_type, Key_generator, Key_compare >::m_element_size
private

◆ m_queue

template<typename Element_type , typename Key_type , typename Key_generator , typename Key_compare = std::less<Key_type>>
Queue_type Bounded_queue< Element_type, Key_type, Key_generator, Key_compare >::m_queue
private

◆ m_sort_keys

template<typename Element_type , typename Key_type , typename Key_generator , typename Key_compare = std::less<Key_type>>
Key_type* Bounded_queue< Element_type, Key_type, Key_generator, Key_compare >::m_sort_keys
private

◆ m_sort_param

template<typename Element_type , typename Key_type , typename Key_generator , typename Key_compare = std::less<Key_type>>
Key_generator* Bounded_queue< Element_type, Key_type, Key_generator, Key_compare >::m_sort_param
private

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