src/rbtree.h

Go to the documentation of this file.
00001 /*
00002  * rbtree.h
00003  *
00004  * Copyright (c) 2004,2005 Martin Murray <mmurray@mon.org>
00005  * All rights reserved.
00006  * 
00007  * Permission to use, copy, modify, and distribute this software for any
00008  * purpose with or without fee is hereby granted, provided that the above
00009  * copyright notice and this permission notice appear in all copies.
00010  *
00011  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00012  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00013  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00014  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00015  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00016  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00017  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.      
00018  *
00019  * $Id: rbtree.h 573 2006-02-14 21:31:21Z murrayma $
00020  */
00021 
00022 #ifndef __RB_TREE__
00023 #define __RB_TREE__
00024 
00025 #define SEARCH_EQUAL    0x1
00026 #define SEARCH_GTEQ     0x2
00027 #define SEARCH_LTEQ     0x3
00028 #define SEARCH_GT       0x4
00029 #define SEARCH_LT       0x5
00030 #define SEARCH_NEXT     0x6
00031 #define SEARCH_PREV     0x7
00032 #define SEARCH_FIRST    0x8
00033 #define SEARCH_LAST     0x9
00034 
00035 #define WALK_PREORDER   0x100
00036 #define WALK_INORDER    0x101
00037 #define WALK_POSTORDER  0x102
00038 
00039 #ifndef DEBUG
00040 typedef void *rbtree;
00041 #else
00042 typedef struct rbtree_node_t {
00043     struct rbtree_node_t *left, *right, *parent;
00044     void *key;
00045     void *data;
00046     int color;
00047     int count;
00048 } rbtree_node;
00049 
00050 typedef struct rbtree_head_t {
00051     struct rbtree_node_t *head;
00052     int (*compare_function) (void *, void *, void *);
00053     void *token;
00054     unsigned int size;
00055 } *rbtree;
00056 #endif
00057 
00058 rbtree rb_init(int (*)(void *, void *, void *), void *);
00059 void rb_destroy(rbtree);
00060 
00061 void rb_insert(rbtree, void *, void *); 
00062 void *rb_find(rbtree, void *);
00063 int rb_exists(rbtree, void *);
00064 void *rb_delete(rbtree, void *);
00065 void *rb_release(rbtree, void (*)(void *, void *, void *), void *);
00066 
00067 void rb_walk(rbtree, int, int (*)(void *, void *, int, void *), void *);
00068 unsigned int rb_size(rbtree);
00069 void *rb_search(rbtree, int, void *);
00070 void *rb_index(rbtree, int);
00071 #endif

Generated on Mon May 28 04:25:25 2007 for BattletechMUX by  doxygen 1.4.7