MySQL 9.1.0
Source Code Documentation
|
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 |
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.
typedef Queue_type::allocator_type Bounded_queue< Element_type, Key_type, Key_generator, Key_compare >::allocator_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 |
|
inline |
|
inline |
Initialize the queue.
max_elements | The size of the queue. | |
sort_param | Sort parameters. We call sort_param->make_sortkey() to generate keys for elements. | |
[in,out] | sort_keys | Array of keys to sort. Must be initialized by caller. Will be filled with pointers to the top-N elements. |
false | OK, true Could not allocate memory. |
We do not take ownership of any of the input pointer arguments.
|
inline |
The number of elements in the queue.
|
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.
opaque | Parameter to send on to make_sortkey(). |
false | OK, true error. |
|
private |
|
private |
|
private |
|
private |