]> git.sur5r.net Git - openldap/blob - include/avl.h
Sync with HEAD
[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-2005 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         signed int              avl_bf;
44         struct avlnode  *avl_left;
45         struct avlnode  *avl_right;
46 };
47
48 #ifdef AVL_INTERNAL
49
50 #define NULLAVL ((Avlnode *) NULL)
51
52 /* balance factor values */
53 #define LH      (-1)
54 #define EH      0
55 #define RH      1
56
57 /* avl routines */
58 #define avl_getone(x)   ((x) == 0 ? 0 : (x)->avl_data)
59 #define avl_onenode(x)  ((x) == 0 || ((x)->avl_left == 0 && (x)->avl_right == 0))
60
61 #endif /* AVL_INTERNALS */
62
63 typedef int             (*AVL_APPLY) LDAP_P((void *, void*));
64 typedef int             (*AVL_CMP) LDAP_P((const void*, const void*));
65 typedef int             (*AVL_DUP) LDAP_P((void*, void*));
66 typedef void    (*AVL_FREE) LDAP_P((void*));
67
68 LDAP_AVL_F( int )
69 avl_free LDAP_P(( Avlnode *root, AVL_FREE dfree ));
70
71 LDAP_AVL_F( int )
72 avl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP));
73
74 LDAP_AVL_F( void* )
75 avl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
76
77 LDAP_AVL_F( void* )
78 avl_find LDAP_P((Avlnode *, const void*, AVL_CMP));
79
80 LDAP_AVL_F( Avlnode* )
81 avl_find2 LDAP_P((Avlnode *, const void*, AVL_CMP));
82
83 LDAP_AVL_F( void* )
84 avl_find_lin LDAP_P((Avlnode *, const void*, AVL_CMP));
85
86 #ifdef AVL_NONREENTRANT
87 LDAP_AVL_F( void* )
88 avl_getfirst LDAP_P((Avlnode *));
89
90 LDAP_AVL_F( void* )
91 avl_getnext LDAP_P((void));
92 #endif
93
94 LDAP_AVL_F( int )
95 avl_dup_error LDAP_P((void*, void*));
96
97 LDAP_AVL_F( int )
98 avl_dup_ok LDAP_P((void*, void*));
99
100 LDAP_AVL_F( int )
101 avl_apply LDAP_P((Avlnode *, AVL_APPLY, void*, int, int));
102
103 LDAP_AVL_F( int )
104 avl_prefixapply LDAP_P((Avlnode *, void*, AVL_CMP, void*, AVL_CMP, void*, int));
105
106 /* apply traversal types */
107 #define AVL_PREORDER    1
108 #define AVL_INORDER     2
109 #define AVL_POSTORDER   3
110 /* what apply returns if it ran out of nodes */
111 #define AVL_NOMORE      (-6)
112
113 LDAP_END_DECL
114
115 #endif /* _AVL */