MySQL  8.0.19
Source Code Documentation
queues.h
Go to the documentation of this file.
1 /* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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) { return queue->root != NULL; }
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif // QUEUES_INCLUDED
queue_remove_all
static void queue_remove_all(QUEUE *queue)
Definition: queues.h:78
QUEUE::first_cmp_arg
void * first_cmp_arg
Definition: queues.h:44
queue
static QUEUE queue
Definition: myisampack.cc:206
queue_remove
uchar * queue_remove(QUEUE *queue, uint idx)
Definition: queues.cc:199
NULL
#define NULL
Definition: types.h:55
init_queue
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)
_downheap
void _downheap(QUEUE *queue, uint idx)
Definition: queues.cc:208
QUEUE::max_elements
uint max_elements
Definition: queues.h:46
PSI_memory_key
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:46
QUEUE
Definition: queues.h:42
queue_compare
int(* queue_compare)(void *, uchar *, uchar *)
Definition: queues.h:66
QUEUE::max_at_top
int max_at_top
Definition: queues.h:48
is_queue_inited
static bool is_queue_inited(QUEUE *queue)
Definition: queues.h:84
my_inttypes.h
reinit_queue
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)
uint
unsigned int uint
Definition: uca-dump.cc:29
queue_insert
void queue_insert(QUEUE *queue, uchar *element)
Definition: queues.cc:180
QUEUE::root
uchar ** root
Definition: queues.h:43
queue_replaced
static void queue_replaced(QUEUE *queue)
Definition: queues.h:60
QUEUE::offset_to_key
uint offset_to_key
Definition: queues.h:47
uchar
unsigned char uchar
Definition: my_inttypes.h:51
queue_is_full
static bool queue_is_full(QUEUE *queue)
Definition: queues.h:80
psi_memory.h
queue_set_max_at_top
static void queue_set_max_at_top(QUEUE *queue, int set_arg)
Definition: queues.h:62
delete_queue
void delete_queue(QUEUE *queue)
Definition: queues.cc:172
QUEUE::auto_extent
uint auto_extent
Definition: queues.h:50
QUEUE::elements
uint elements
Definition: queues.h:45
compare
static int compare(size_t a, size_t b)
Function to compare two size_t integers for their relative order.
Definition: rpl_utility.cc:103
queue_fix
void queue_fix(QUEUE *queue)
Definition: queues.cc:256
QUEUE::compare
int(* compare)(void *, uchar *, uchar *)
Definition: queues.h:49