Eneboo - Documentación para desarrolladores
|
00001 /* Copyright (C) 2000 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* 00018 Code for generell handling of priority Queues. 00019 Implemention of queues from "Algoritms in C" by Robert Sedgewick. 00020 Copyright Monty Program KB. 00021 By monty. 00022 */ 00023 00024 #ifndef _queues_h 00025 #define _queues_h 00026 #ifdef __cplusplus 00027 extern "C" { 00028 #endif 00029 00030 typedef struct st_queue { 00031 byte **root; 00032 void *first_cmp_arg; 00033 uint elements; 00034 uint max_elements; 00035 uint offset_to_key; /* compare is done on element+offset */ 00036 int max_at_top; /* Set if queue_top gives max */ 00037 int (*compare)(void *, byte *,byte *); 00038 } QUEUE; 00039 00040 #define queue_top(queue) ((queue)->root[1]) 00041 #define queue_element(queue,index) ((queue)->root[index+1]) 00042 #define queue_end(queue) ((queue)->root[(queue)->elements]) 00043 #define queue_replaced(queue) _downheap(queue,1) 00044 typedef int (*queue_compare)(void *,byte *, byte *); 00045 00046 int init_queue(QUEUE *queue,uint max_elements,uint offset_to_key, 00047 pbool max_at_top, queue_compare compare, 00048 void *first_cmp_arg); 00049 int reinit_queue(QUEUE *queue,uint max_elements,uint offset_to_key, 00050 pbool max_at_top, queue_compare compare, 00051 void *first_cmp_arg); 00052 int resize_queue(QUEUE *queue, uint max_elements); 00053 void delete_queue(QUEUE *queue); 00054 void queue_insert(QUEUE *queue,byte *element); 00055 byte *queue_remove(QUEUE *queue,uint idx); 00056 void _downheap(QUEUE *queue,uint idx); 00057 void queue_fix(QUEUE *queue); 00058 #define is_queue_inited(queue) ((queue)->root != 0) 00059 00060 #ifdef __cplusplus 00061 } 00062 #endif 00063 #endif