1 /* avl.h - avl tree definitions */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2006 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
16 /* Portions Copyright (c) 1993 Regents of the University of Michigan.
17 * All rights reserved.
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.
31 #include <ldap_cdefs.h>
34 * this structure represents a generic avl tree node.
39 typedef struct avlnode Avlnode;
43 struct avlnode *avl_link[2];
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]
55 #define NULLAVL ((Avlnode *) NULL)
57 /* balance factor values */
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))
70 #endif /* AVL_INTERNALS */
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)
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*));
83 avl_free LDAP_P(( Avlnode *root, AVL_FREE dfree ));
86 avl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP));
89 avl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
92 avl_find LDAP_P((Avlnode *, const void*, AVL_CMP));
94 LDAP_AVL_F( Avlnode* )
95 avl_find2 LDAP_P((Avlnode *, const void*, AVL_CMP));
98 avl_find_lin LDAP_P((Avlnode *, const void*, AVL_CMP));
100 #ifdef AVL_NONREENTRANT
102 avl_getfirst LDAP_P((Avlnode *));
105 avl_getnext LDAP_P((void));
109 avl_dup_error LDAP_P((void*, void*));
112 avl_dup_ok LDAP_P((void*, void*));
115 avl_apply LDAP_P((Avlnode *, AVL_APPLY, void*, int, int));
118 avl_prefixapply LDAP_P((Avlnode *, void*, AVL_CMP, void*, AVL_CMP, void*, int));
121 tavl_free LDAP_P(( Avlnode *root, AVL_FREE dfree ));
124 tavl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP));
127 tavl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
130 tavl_find LDAP_P((Avlnode *, const void*, AVL_CMP));
132 LDAP_AVL_F( Avlnode* )
133 tavl_find2 LDAP_P((Avlnode *, const void*, AVL_CMP));
135 #define TAVL_DIR_LEFT 0
136 #define TAVL_DIR_RIGHT 1
138 LDAP_AVL_F( Avlnode* )
139 tavl_end LDAP_P((Avlnode *, int direction ));
141 LDAP_AVL_F( Avlnode* )
142 tavl_next LDAP_P((Avlnode *, int direction ));
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)