16 #ifndef BOUNDED_QUEUE_INCLUDED
17 #define BOUNDED_QUEUE_INCLUDED
20 #include "my_global.h"
41 template<
typename Element_type,
typename Key_type>
47 memset(&m_queue, 0,
sizeof(m_queue));
52 delete_queue(&m_queue);
95 int init(ha_rows max_elements,
bool max_at_top,
98 Key_type **sort_keys);
107 void push(Element_type *element);
121 if (queue_is_full((&m_queue)))
122 queue_remove(&m_queue, 0);
123 DBUG_ASSERT(m_queue.elements > 0);
124 if (m_queue.elements == 0)
126 return reinterpret_cast<Key_type**
>(queue_remove(&m_queue, 0));
140 Key_type **m_sort_keys;
141 size_t m_compare_length;
148 template<
typename Element_type,
typename Key_type>
152 size_t compare_length,
153 keymaker_function keymaker,
155 Key_type **sort_keys)
157 DBUG_ASSERT(sort_keys != NULL);
159 m_sort_keys= sort_keys;
160 m_compare_length= compare_length;
161 m_keymaker= keymaker;
162 m_sort_param= sort_param;
164 if (max_elements >= (UINT_MAX - 1))
168 reinterpret_cast<compare_function
>(get_ptr_compare(compare_length));
170 DBUG_EXECUTE_IF(
"bounded_queue_init_fail",
171 DBUG_SET(
"+d,simulate_out_of_memory"););
174 return init_queue(&m_queue, (uint) max_elements + 1,
176 reinterpret_cast<queue_compare>(compare),
181 template<
typename Element_type,
typename Key_type>
184 DBUG_ASSERT(is_initialized());
185 if (queue_is_full((&m_queue)))
188 Key_type **pq_top=
reinterpret_cast<Key_type **
>(queue_top(&m_queue));
189 (*m_keymaker)(m_sort_param, *pq_top, element);
190 queue_replaced(&m_queue);
193 (*m_keymaker)(m_sort_param, m_sort_keys[m_queue.elements], element);
194 queue_insert(&m_queue,
195 reinterpret_cast<uchar*>(&m_sort_keys[m_queue.elements]));
199 #endif // BOUNDED_QUEUE_INCLUDED