MySQL 8.4.0
Source Code Documentation
queues.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef QUEUES_INCLUDED
25#define QUEUES_INCLUDED
26
27/**
28 @file storage/myisam/queues.h
29 Code for handling of priority queues.
30 Implementation of queues from "Algorithms in C" by Robert Sedgewick.
31*/
32
33#include <stddef.h>
34#include <sys/types.h>
35
36#include "my_inttypes.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43struct QUEUE {
48 uint offset_to_key; /* compare is done on element+offset */
49 int max_at_top; /* Normally 1, set to -1 if queue_top gives max */
50 int (*compare)(void *, uchar *, uchar *);
52};
53
54void _downheap(QUEUE *queue, uint idx);
55void queue_fix(QUEUE *queue);
56
57#define queue_top(queue) ((queue)->root[1])
58#define queue_element(queue, index) ((queue)->root[index + 1])
59#define queue_end(queue) ((queue)->root[(queue)->elements])
60
61static inline void queue_replaced(QUEUE *queue) { _downheap(queue, 1); }
62
63static inline void queue_set_max_at_top(QUEUE *queue, int set_arg) {
64 queue->max_at_top = set_arg ? -1 : 1;
65}
66
67typedef int (*queue_compare)(void *, uchar *, uchar *);
68
69int init_queue(QUEUE *queue, PSI_memory_key psi_key, uint max_elements,
70 uint offset_to_key, bool max_at_top, queue_compare compare,
71 void *first_cmp_arg);
72int reinit_queue(QUEUE *queue, PSI_memory_key psi_key, uint max_elements,
73 uint offset_to_key, bool max_at_top, queue_compare compare,
74 void *first_cmp_arg);
76void queue_insert(QUEUE *queue, uchar *element);
77uchar *queue_remove(QUEUE *queue, uint idx);
78
79static inline void queue_remove_all(QUEUE *queue) { queue->elements = 0; }
80
81static inline bool queue_is_full(QUEUE *queue) {
82 return queue->elements == queue->max_elements;
83}
84
85static inline bool is_queue_inited(QUEUE *queue) {
86 return queue->root != nullptr;
87}
88
89#ifdef __cplusplus
90}
91#endif
92
93#endif // QUEUES_INCLUDED
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
static QUEUE queue
Definition: myisampack.cc:210
Performance schema instrumentation interface.
static bool queue_is_full(QUEUE *queue)
Definition: queues.h:81
static bool is_queue_inited(QUEUE *queue)
Definition: queues.h:85
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:210
uchar * queue_remove(QUEUE *queue, uint idx)
Definition: queues.cc:201
void delete_queue(QUEUE *queue)
Definition: queues.cc:174
void queue_fix(QUEUE *queue)
Definition: queues.cc:258
static void queue_replaced(QUEUE *queue)
Definition: queues.h:61
void queue_insert(QUEUE *queue, uchar *element)
Definition: queues.cc:182
int(* queue_compare)(void *, uchar *, uchar *)
Definition: queues.h:67
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:79
static void queue_set_max_at_top(QUEUE *queue, int set_arg)
Definition: queues.h:63
static int compare(size_t a, size_t b)
Function to compare two size_t integers for their relative order.
Definition: rpl_utility.cc:107
Definition: queues.h:43
uint auto_extent
Definition: queues.h:51
uchar ** root
Definition: queues.h:44
int(* compare)(void *, uchar *, uchar *)
Definition: queues.h:50
void * first_cmp_arg
Definition: queues.h:45
int max_at_top
Definition: queues.h:49
uint max_elements
Definition: queues.h:47
uint elements
Definition: queues.h:46
uint offset_to_key
Definition: queues.h:48