~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/queues.h

  • Committer: Brian Aker
  • Date: 2009-03-22 21:27:04 UTC
  • mfrom: (960.2.22 mordred)
  • Revision ID: brian@tangent.org-20090322212704-ysn4mkkjg2u9kv22
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 {
30
 
  unsigned char **root;
31
 
  void *first_cmp_arg;
32
 
  uint32_t elements;
33
 
  uint32_t max_elements;
34
 
  uint32_t 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 *, unsigned char *,unsigned char *);
37
 
  uint32_t auto_extent;
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
47
 
typedef int (*queue_compare)(void *,unsigned char *, unsigned char *);
48
 
 
49
 
int init_queue(QUEUE *queue,uint32_t max_elements,uint32_t offset_to_key,
50
 
               bool max_at_top, queue_compare compare,
51
 
               void *first_cmp_arg);
52
 
int init_queue_ex(QUEUE *queue,uint32_t max_elements,uint32_t offset_to_key,
53
 
                  bool max_at_top, queue_compare compare,
54
 
                  void *first_cmp_arg, uint32_t auto_extent);
55
 
int reinit_queue(QUEUE *queue,uint32_t max_elements,uint32_t offset_to_key,
56
 
                 bool max_at_top, queue_compare compare,
57
 
                 void *first_cmp_arg);
58
 
int resize_queue(QUEUE *queue, uint32_t max_elements);
59
 
void delete_queue(QUEUE *queue);
60
 
void queue_insert(QUEUE *queue,unsigned char *element);
61
 
int queue_insert_safe(QUEUE *queue, unsigned char *element);
62
 
unsigned char *queue_remove(QUEUE *queue,uint32_t 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,uint32_t idx);
66
 
void queue_fix(QUEUE *queue);
67
 
#define is_queue_inited(queue) ((queue)->root != 0)
68
 
 
69
 
#ifdef  __cplusplus
70
 
}
71
 
#endif
72
 
#endif