1
/* Copyright (C) 2000 MySQL AB
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
Code for generell handling of priority Queues.
18
Implemention of queues from "Algoritms in C" by Robert Sedgewick.
19
Copyright Monty Program KB.
29
typedef struct st_queue {
34
uint offset_to_key; /* compare is done on element+offset */
35
int max_at_top; /* Normally 1, set to -1 if queue_top gives max */
36
int (*compare)(void *, uchar *,uchar *);
40
#define queue_top(queue) ((queue)->root[1])
41
#define queue_element(queue,index) ((queue)->root[index+1])
42
#define queue_end(queue) ((queue)->root[(queue)->elements])
43
#define queue_replaced(queue) _downheap(queue,1)
44
#define queue_set_cmp_arg(queue, set_arg) (queue)->first_cmp_arg= set_arg
45
#define queue_set_max_at_top(queue, set_arg) \
46
(queue)->max_at_top= set_arg ? -1 : 1
47
typedef int (*queue_compare)(void *,uchar *, uchar *);
49
int init_queue(QUEUE *queue,uint max_elements,uint offset_to_key,
50
pbool max_at_top, queue_compare compare,
52
int init_queue_ex(QUEUE *queue,uint max_elements,uint offset_to_key,
53
pbool max_at_top, queue_compare compare,
54
void *first_cmp_arg, uint auto_extent);
55
int reinit_queue(QUEUE *queue,uint max_elements,uint offset_to_key,
56
pbool max_at_top, queue_compare compare,
58
int resize_queue(QUEUE *queue, uint max_elements);
59
void delete_queue(QUEUE *queue);
60
void queue_insert(QUEUE *queue,uchar *element);
61
int queue_insert_safe(QUEUE *queue, uchar *element);
62
uchar *queue_remove(QUEUE *queue,uint idx);
63
#define queue_remove_all(queue) { (queue)->elements= 0; }
64
#define queue_is_full(queue) (queue->elements == queue->max_elements)
65
void _downheap(QUEUE *queue,uint idx);
66
void queue_fix(QUEUE *queue);
67
#define is_queue_inited(queue) ((queue)->root != 0)