]> git.sur5r.net Git - openldap/blob - include/avl.h
For ITS#157: Added LDAP backend for slapd, which also required adding
[openldap] / include / avl.h
1 /*
2  * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted only
6  * as authorized by the OpenLDAP Public License.  A copy of this
7  * license is available at http://www.OpenLDAP.org/license.html or
8  * in file LICENSE in the top-level directory of the distribution.
9  */
10 /* Portions
11  * Copyright (c) 1993 Regents of the University of Michigan.
12  * All rights reserved.
13  *
14  * Redistribution and use in source and binary forms are permitted
15  * provided that this notice is preserved and that due credit is given
16  * to the University of Michigan at Ann Arbor. The name of the University
17  * may not be used to endorse or promote products derived from this
18  * software without specific prior written permission. This software
19  * is provided ``as is'' without express or implied warranty.
20  */
21 /* avl.h - avl tree definitions */
22
23
24 #ifndef _AVL
25 #define _AVL
26
27 #include <ldap_cdefs.h>
28
29 /*
30  * this structure represents a generic avl tree node.
31  */
32
33 LDAP_BEGIN_DECL
34
35 typedef struct avlnode {
36         void*           avl_data;
37         signed char             avl_bf;
38         struct avlnode  *avl_left;
39         struct avlnode  *avl_right;
40 } Avlnode;
41
42 #define NULLAVL ((Avlnode *) NULL)
43
44 /* balance factor values */
45 #define LH      (-1)
46 #define EH      0
47 #define RH      1
48
49 /* avl routines */
50 #define avl_getone(x)   ((x) == 0 ? 0 : (x)->avl_data)
51 #define avl_onenode(x)  ((x) == 0 || ((x)->avl_left == 0 && (x)->avl_right == 0))
52
53 typedef int             (*AVL_APPLY) LDAP_P((void *, void*));
54 typedef int             (*AVL_CMP) LDAP_P((void*, void*));
55 typedef int             (*AVL_DUP) LDAP_P((void*, void*));
56 typedef void    (*AVL_FREE) LDAP_P((void*));
57
58 LDAP_F( int )
59 avl_free LDAP_P(( Avlnode *root, AVL_FREE dfree ));
60
61 LDAP_F( int )
62 avl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP));
63
64 LDAP_F( void* )
65 avl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
66
67 LDAP_F( void* )
68 avl_find LDAP_P((Avlnode *, void*, AVL_CMP));
69
70 LDAP_F( void* )
71 avl_find_lin LDAP_P((Avlnode *, void*, AVL_CMP));
72
73 LDAP_F( void* )
74 avl_getfirst LDAP_P((Avlnode *));
75
76 #ifdef AVL_REENTRANT
77 /* ??? avl.c does not provide this version ??? */
78 LDAP_F( void* )
79 avl_getnext LDAP_P((Avlnode *, void* ));
80 #else
81 LDAP_F( void* )
82 avl_getnext LDAP_P((void));
83 #endif
84
85 LDAP_F( int )
86 avl_dup_error LDAP_P((void*, void*));
87
88 LDAP_F( int )
89 avl_dup_ok LDAP_P((void*, void*));
90
91 LDAP_F( int )
92 avl_apply LDAP_P((Avlnode *, AVL_APPLY, void*, int, int));
93
94 LDAP_F( int )
95 avl_prefixapply LDAP_P((Avlnode *, void*, AVL_CMP, void*, AVL_CMP, void*, int));
96
97 /* apply traversal types */
98 #define AVL_PREORDER    1
99 #define AVL_INORDER     2
100 #define AVL_POSTORDER   3
101 /* what apply returns if it ran out of nodes */
102 #define AVL_NOMORE      (-6)
103
104 LDAP_END_DECL
105
106 #endif /* _AVL */