MySQL  8.0.28
Source Code Documentation
queues.h
Go to the documentation of this file.
1 /* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef QUEUES_INCLUDED
24 #define QUEUES_INCLUDED
25 
26 /**
27  @file storage/myisam/queues.h
28  Code for handling of priority queues.
29  Implementation of queues from "Algoritms in C" by Robert Sedgewick.
30 */
31 
32 #include <stddef.h>
33 #include <sys/types.h>
34 
35 #include "my_inttypes.h"
36 #include "mysql/psi/psi_memory.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 struct QUEUE {
47  uint offset_to_key; /* compare is done on element+offset */
48  int max_at_top; /* Normally 1, set to -1 if queue_top gives max */
49  int (*compare)(void *, uchar *, uchar *);
51 };
52 
53 void _downheap(QUEUE *queue, uint idx);
54 void queue_fix(QUEUE *queue);
55 
56 #define queue_top(queue) ((queue)->root[1])
57 #define queue_element(queue, index) ((queue)->root[index + 1])
58 #define queue_end(queue) ((queue)->root[(queue)->elements])
59 
60 static inline void queue_replaced(QUEUE *queue) { _downheap(queue, 1); }
61 
62 static inline void queue_set_max_at_top(QUEUE *queue, int set_arg) {
63  queue->max_at_top = set_arg ? -1 : 1;
64 }
65 
66 typedef int (*queue_compare)(void *, uchar *, uchar *);
67 
68 int init_queue(QUEUE *queue, PSI_memory_key psi_key, uint max_elements,
69  uint offset_to_key, bool max_at_top, queue_compare compare,
70  void *first_cmp_arg);
71 int reinit_queue(QUEUE *queue, PSI_memory_key psi_key, uint max_elements,
72  uint offset_to_key, bool max_at_top, queue_compare compare,
73  void *first_cmp_arg);
74 void delete_queue(QUEUE *queue);
75 void queue_insert(QUEUE *queue, uchar *element);
77 
78 static inline void queue_remove_all(QUEUE *queue) { queue->elements = 0; }
79 
80 static inline bool queue_is_full(QUEUE *queue) {
81  return queue->elements == queue->max_elements;
82 }
83 
84 static inline bool is_queue_inited(QUEUE *queue) {
85  return queue->root != nullptr;
86 }
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif // QUEUES_INCLUDED
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:48
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:51
static QUEUE queue
Definition: myisampack.cc:206
Performance schema instrumentation interface.
static bool queue_is_full(QUEUE *queue)
Definition: queues.h:80
uchar * queue_remove(QUEUE *queue, uint idx)
Definition: queues.cc:200
static bool is_queue_inited(QUEUE *queue)
Definition: queues.h:84
int init_queue(QUEUE *queue, PSI_memory_key psi_key, uint max_elements, uint offset_to_key, bool max_at_top, queue_compare compare, void *first_cmp_arg)
void _downheap(QUEUE *queue, uint idx)
Definition: queues.cc:209
void delete_queue(QUEUE *queue)
Definition: queues.cc:173
void queue_fix(QUEUE *queue)
Definition: queues.cc:257
static void queue_replaced(QUEUE *queue)
Definition: queues.h:60
void queue_insert(QUEUE *queue, uchar *element)
Definition: queues.cc:181
int(* queue_compare)(void *, uchar *, uchar *)
Definition: queues.h:66
int reinit_queue(QUEUE *queue, PSI_memory_key psi_key, uint max_elements, uint offset_to_key, bool max_at_top, queue_compare compare, void *first_cmp_arg)
static void queue_remove_all(QUEUE *queue)
Definition: queues.h:78
static void queue_set_max_at_top(QUEUE *queue, int set_arg)
Definition: queues.h:62
static int compare(size_t a, size_t b)
Function to compare two size_t integers for their relative order.
Definition: rpl_utility.cc:104
Definition: queues.h:42
uint auto_extent
Definition: queues.h:50
uchar ** root
Definition: queues.h:43
int(* compare)(void *, uchar *, uchar *)
Definition: queues.h:49
void * first_cmp_arg
Definition: queues.h:44
int max_at_top
Definition: queues.h:48
uint max_elements
Definition: queues.h:46
uint elements
Definition: queues.h:45
uint offset_to_key
Definition: queues.h:47
unsigned int uint
Definition: uca-dump.cc:29