~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
#ifdef	__cplusplus
26
extern "C" {
27
#endif
28
29
typedef struct st_queue {
481 by Brian Aker
Remove all of uchar.
30
  unsigned char **root;
1 by brian
clean slate
31
  void *first_cmp_arg;
482 by Brian Aker
Remove uint.
32
  uint32_t elements;
33
  uint32_t max_elements;
34
  uint32_t offset_to_key;	/* compare is done on element+offset */
1 by brian
clean slate
35
  int max_at_top;	/* Normally 1, set to -1 if queue_top gives max */
481 by Brian Aker
Remove all of uchar.
36
  int  (*compare)(void *, unsigned char *,unsigned char *);
482 by Brian Aker
Remove uint.
37
  uint32_t auto_extent;
1 by brian
clean slate
38
} QUEUE;
39
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
481 by Brian Aker
Remove all of uchar.
47
typedef int (*queue_compare)(void *,unsigned char *, unsigned char *);
1 by brian
clean slate
48
482 by Brian Aker
Remove uint.
49
int init_queue(QUEUE *queue,uint32_t max_elements,uint32_t offset_to_key,
154 by Brian Aker
Removed oddball types in my_global.h
50
               bool max_at_top, queue_compare compare,
51
               void *first_cmp_arg);
482 by Brian Aker
Remove uint.
52
int init_queue_ex(QUEUE *queue,uint32_t max_elements,uint32_t offset_to_key,
154 by Brian Aker
Removed oddball types in my_global.h
53
                  bool max_at_top, queue_compare compare,
482 by Brian Aker
Remove uint.
54
                  void *first_cmp_arg, uint32_t auto_extent);
55
int reinit_queue(QUEUE *queue,uint32_t max_elements,uint32_t offset_to_key,
154 by Brian Aker
Removed oddball types in my_global.h
56
                 bool max_at_top, queue_compare compare,
1 by brian
clean slate
57
                 void *first_cmp_arg);
482 by Brian Aker
Remove uint.
58
int resize_queue(QUEUE *queue, uint32_t max_elements);
1 by brian
clean slate
59
void delete_queue(QUEUE *queue);
481 by Brian Aker
Remove all of uchar.
60
void queue_insert(QUEUE *queue,unsigned char *element);
61
int queue_insert_safe(QUEUE *queue, unsigned char *element);
482 by Brian Aker
Remove uint.
62
unsigned char *queue_remove(QUEUE *queue,uint32_t idx);
1 by brian
clean slate
63
#define queue_remove_all(queue) { (queue)->elements= 0; }
64
#define queue_is_full(queue) (queue->elements == queue->max_elements)
482 by Brian Aker
Remove uint.
65
void _downheap(QUEUE *queue,uint32_t idx);
1 by brian
clean slate
66
void queue_fix(QUEUE *queue);
67
#define is_queue_inited(queue) ((queue)->root != 0)
68
69
#ifdef	__cplusplus
70
}
71
#endif
72
#endif