* Removed all Id tags.
[cacao.git] / src / toolbox / avl.h
1 /* src/toolbox/avl.h - AVL tree implementation
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #ifndef _AVL_H
29 #define _AVL_H
30
31 #include "config.h"
32
33 #include "vm/types.h"
34
35 #include "vm/global.h"
36
37
38 /* define direction in an AVL node ********************************************/
39
40 #define AVL_LEFT     0
41 #define AVL_RIGHT    1
42
43
44 /* tree comparator prototype **************************************************/
45
46 typedef s4 avl_comparator(const void *treenode, const void *node);
47
48
49 /* forward typedefs ***********************************************************/
50
51 typedef struct avl_tree_t avl_tree_t;
52 typedef struct avl_node_t avl_node_t;
53
54
55 /* avl_tree_t *****************************************************************/
56
57 struct avl_tree_t {
58 #if defined(ENABLE_THREADS)
59         java_object_t     *lock;            /* threads lock object                */
60 #endif
61         avl_node_t        *root;            /* pointer to root node               */
62         avl_comparator    *comparator;      /* pointer to comparison function     */
63         s4                 entries;         /* contains number of entries         */
64 };
65
66
67 /* avl_node_t *****************************************************************/
68
69 struct avl_node_t {
70         void       *data;                   /* pointer to data structure          */
71         s4          balance;                /* the range of the field is -2...2   */
72         avl_node_t *childs[2];              /* pointers to the child nodes        */
73 };
74
75
76 /* function prototypes ********************************************************/
77
78 avl_tree_t *avl_create(avl_comparator *comparator);
79 bool        avl_insert(avl_tree_t *tree, void *data);
80 void       *avl_find(avl_tree_t *tree, void *data);
81
82 #if !defined(NDEBUG)
83 void        avl_dump(avl_node_t* node, s4 indent);
84 #endif
85
86 #endif /* _AVL_H */
87
88
89 /*
90  * These are local overrides for various environment variables in Emacs.
91  * Please do not remove this and leave it at the end of the file, where
92  * Emacs will automagically detect them.
93  * ---------------------------------------------------------------------
94  * Local variables:
95  * mode: c
96  * indent-tabs-mode: t
97  * c-basic-offset: 4
98  * tab-width: 4
99  * End:
100  */