MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
queues.h
1 /* Copyright (c) 2000, 2010, 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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 /*
17  Code for generell handling of priority Queues.
18  Implemention of queues from "Algoritms in C" by Robert Sedgewick.
19  Copyright Monty Program KB.
20  By monty.
21 */
22 
23 #ifndef _queues_h
24 #define _queues_h
25 
26 #include "my_global.h" /* uchar */
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 typedef struct st_queue {
33  uchar **root;
34  void *first_cmp_arg;
35  uint elements;
36  uint max_elements;
37  uint offset_to_key; /* compare is done on element+offset */
38  int max_at_top; /* Normally 1, set to -1 if queue_top gives max */
39  int (*compare)(void *, uchar *,uchar *);
40  uint auto_extent;
41 } QUEUE;
42 
43 #define queue_top(queue) ((queue)->root[1])
44 #define queue_element(queue,index) ((queue)->root[index+1])
45 #define queue_end(queue) ((queue)->root[(queue)->elements])
46 #define queue_replaced(queue) _downheap(queue,1)
47 #define queue_set_cmp_arg(queue, set_arg) (queue)->first_cmp_arg= set_arg
48 #define queue_set_max_at_top(queue, set_arg) \
49  (queue)->max_at_top= set_arg ? -1 : 1
50 typedef int (*queue_compare)(void *,uchar *, uchar *);
51 
52 int init_queue(QUEUE *queue,uint max_elements,uint offset_to_key,
53  pbool max_at_top, queue_compare compare,
54  void *first_cmp_arg);
55 int init_queue_ex(QUEUE *queue,uint max_elements,uint offset_to_key,
56  pbool max_at_top, queue_compare compare,
57  void *first_cmp_arg, uint auto_extent);
58 int reinit_queue(QUEUE *queue,uint max_elements,uint offset_to_key,
59  pbool max_at_top, queue_compare compare,
60  void *first_cmp_arg);
61 int resize_queue(QUEUE *queue, uint max_elements);
62 void delete_queue(QUEUE *queue);
63 void queue_insert(QUEUE *queue,uchar *element);
64 int queue_insert_safe(QUEUE *queue, uchar *element);
65 uchar *queue_remove(QUEUE *queue,uint idx);
66 #define queue_remove_all(queue) { (queue)->elements= 0; }
67 #define queue_is_full(queue) (queue->elements == queue->max_elements)
68 void _downheap(QUEUE *queue,uint idx);
69 void queue_fix(QUEUE *queue);
70 #define is_queue_inited(queue) ((queue)->root != 0)
71 
72 #ifdef __cplusplus
73 }
74 #endif
75 #endif