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