]> git.sur5r.net Git - openldap/blob - include/avl.h
Fix prev commit
[openldap] / include / avl.h
1 /* avl.h - avl tree definitions */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2008 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* Portions Copyright (c) 1993 Regents of the University of Michigan.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms are permitted
20  * provided that this notice is preserved and that due credit is given
21  * to the University of Michigan at Ann Arbor. The name of the University
22  * may not be used to endorse or promote products derived from this
23  * software without specific prior written permission. This software
24  * is provided ``as is'' without express or implied warranty.
25  */
26
27
28 #ifndef _AVL
29 #define _AVL
30
31 #include <ldap_cdefs.h>
32
33 /*
34  * this structure represents a generic avl tree node.
35  */
36
37 LDAP_BEGIN_DECL
38
39 typedef struct avlnode Avlnode;
40
41 struct avlnode {
42         void*           avl_data;
43         struct avlnode  *avl_link[2];
44         char            avl_bits[2];
45         signed char             avl_bf;
46 };
47
48 #define avl_left        avl_link[0]
49 #define avl_right       avl_link[1]
50 #define avl_lbit        avl_bits[0]
51 #define avl_rbit        avl_bits[1]
52
53 #ifdef AVL_INTERNAL
54
55 #define NULLAVL ((Avlnode *) NULL)
56
57 /* balance factor values */
58 #define LH      (-1)
59 #define EH      0
60 #define RH      1
61
62 /* thread bits */
63 #define AVL_THREAD      0
64 #define AVL_CHILD       1
65
66 /* avl routines */
67 #define avl_getone(x)   ((x) == 0 ? 0 : (x)->avl_data)
68 #define avl_onenode(x)  ((x) == 0 || ((x)->avl_left == 0 && (x)->avl_right == 0))
69
70 #endif /* AVL_INTERNALS */
71
72 #define avl_child(x,dir)        ((x)->avl_bits[dir]) == AVL_CHILD ? \
73         (x)->avl_link[dir] : NULL
74 #define avl_lchild(x)   avl_child(x,0)
75 #define avl_rchild(x)   avl_child(x,1)
76
77 typedef int             (*AVL_APPLY) LDAP_P((void *, void*));
78 typedef int             (*AVL_CMP) LDAP_P((const void*, const void*));
79 typedef int             (*AVL_DUP) LDAP_P((void*, void*));
80 typedef void    (*AVL_FREE) LDAP_P((void*));
81
82 LDAP_AVL_F( int )
83 avl_free LDAP_P(( Avlnode *root, AVL_FREE dfree ));
84
85 LDAP_AVL_F( int )
86 avl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP));
87
88 LDAP_AVL_F( void* )
89 avl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
90
91 LDAP_AVL_F( void* )
92 avl_find LDAP_P((Avlnode *, const void*, AVL_CMP));
93
94 LDAP_AVL_F( Avlnode* )
95 avl_find2 LDAP_P((Avlnode *, const void*, AVL_CMP));
96
97 LDAP_AVL_F( void* )
98 avl_find_lin LDAP_P((Avlnode *, const void*, AVL_CMP));
99
100 #ifdef AVL_NONREENTRANT
101 LDAP_AVL_F( void* )
102 avl_getfirst LDAP_P((Avlnode *));
103
104 LDAP_AVL_F( void* )
105 avl_getnext LDAP_P((void));
106 #endif
107
108 LDAP_AVL_F( int )
109 avl_dup_error LDAP_P((void*, void*));
110
111 LDAP_AVL_F( int )
112 avl_dup_ok LDAP_P((void*, void*));
113
114 LDAP_AVL_F( int )
115 avl_apply LDAP_P((Avlnode *, AVL_APPLY, void*, int, int));
116
117 LDAP_AVL_F( int )
118 avl_prefixapply LDAP_P((Avlnode *, void*, AVL_CMP, void*, AVL_CMP, void*, int));
119
120 LDAP_AVL_F( int )
121 tavl_free LDAP_P(( Avlnode *root, AVL_FREE dfree ));
122
123 LDAP_AVL_F( int )
124 tavl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP));
125
126 LDAP_AVL_F( void* )
127 tavl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
128
129 LDAP_AVL_F( void* )
130 tavl_find LDAP_P((Avlnode *, const void*, AVL_CMP));
131
132 LDAP_AVL_F( Avlnode* )
133 tavl_find2 LDAP_P((Avlnode *, const void*, AVL_CMP));
134
135 #define TAVL_DIR_LEFT   0
136 #define TAVL_DIR_RIGHT  1
137
138 LDAP_AVL_F( Avlnode* )
139 tavl_end LDAP_P((Avlnode *, int direction ));
140
141 LDAP_AVL_F( Avlnode* )
142 tavl_next LDAP_P((Avlnode *, int direction ));
143
144 /* apply traversal types */
145 #define AVL_PREORDER    1
146 #define AVL_INORDER     2
147 #define AVL_POSTORDER   3
148 /* what apply returns if it ran out of nodes */
149 #define AVL_NOMORE      (-6)
150
151 LDAP_END_DECL
152
153 #endif /* _AVL */