Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / include / avl.h
blobc8c8903f5fc8a74bdfa92a8e45696e851e88c88d
1 /* avl.h - avl tree definitions */
2 /* $OpenLDAP: pkg/ldap/include/avl.h,v 1.29.2.4 2008/02/11 23:26:40 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 The OpenLDAP Foundation.
6 * All rights reserved.
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.
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.
28 #ifndef _AVL
29 #define _AVL
31 #include <ldap_cdefs.h>
34 * this structure represents a generic avl tree node.
37 LDAP_BEGIN_DECL
39 typedef struct avlnode Avlnode;
41 struct avlnode {
42 void* avl_data;
43 struct avlnode *avl_link[2];
44 char avl_bits[2];
45 signed char avl_bf;
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]
53 #ifdef AVL_INTERNAL
55 #define NULLAVL ((Avlnode *) NULL)
57 /* balance factor values */
58 #define LH (-1)
59 #define EH 0
60 #define RH 1
62 #define avl_bf2str(bf) ((bf) == -1 ? "LH" : (bf) == 0 ? "EH" : (bf) == 1 ? "RH" : "(unknown)" )
64 /* thread bits */
65 #define AVL_THREAD 0
66 #define AVL_CHILD 1
68 /* avl routines */
69 #define avl_getone(x) ((x) == 0 ? 0 : (x)->avl_data)
70 #define avl_onenode(x) ((x) == 0 || ((x)->avl_left == 0 && (x)->avl_right == 0))
72 #endif /* AVL_INTERNALS */
74 #define avl_child(x,dir) ((x)->avl_bits[dir]) == AVL_CHILD ? \
75 (x)->avl_link[dir] : NULL
76 #define avl_lchild(x) avl_child(x,0)
77 #define avl_rchild(x) avl_child(x,1)
79 typedef int (*AVL_APPLY) LDAP_P((void *, void*));
80 typedef int (*AVL_CMP) LDAP_P((const void*, const void*));
81 typedef int (*AVL_DUP) LDAP_P((void*, void*));
82 typedef void (*AVL_FREE) LDAP_P((void*));
84 LDAP_AVL_F( int )
85 avl_free LDAP_P(( Avlnode *root, AVL_FREE dfree ));
87 LDAP_AVL_F( int )
88 avl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP));
90 LDAP_AVL_F( void* )
91 avl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
93 LDAP_AVL_F( void* )
94 avl_find LDAP_P((Avlnode *, const void*, AVL_CMP));
96 LDAP_AVL_F( Avlnode* )
97 avl_find2 LDAP_P((Avlnode *, const void*, AVL_CMP));
99 LDAP_AVL_F( void* )
100 avl_find_lin LDAP_P((Avlnode *, const void*, AVL_CMP));
102 #ifdef AVL_NONREENTRANT
103 LDAP_AVL_F( void* )
104 avl_getfirst LDAP_P((Avlnode *));
106 LDAP_AVL_F( void* )
107 avl_getnext LDAP_P((void));
108 #endif
110 LDAP_AVL_F( int )
111 avl_dup_error LDAP_P((void*, void*));
113 LDAP_AVL_F( int )
114 avl_dup_ok LDAP_P((void*, void*));
116 LDAP_AVL_F( int )
117 avl_apply LDAP_P((Avlnode *, AVL_APPLY, void*, int, int));
119 LDAP_AVL_F( int )
120 avl_prefixapply LDAP_P((Avlnode *, void*, AVL_CMP, void*, AVL_CMP, void*, int));
122 LDAP_AVL_F( int )
123 tavl_free LDAP_P(( Avlnode *root, AVL_FREE dfree ));
125 LDAP_AVL_F( int )
126 tavl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP));
128 LDAP_AVL_F( void* )
129 tavl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
131 LDAP_AVL_F( void* )
132 tavl_find LDAP_P((Avlnode *, const void*, AVL_CMP));
134 LDAP_AVL_F( Avlnode* )
135 tavl_find2 LDAP_P((Avlnode *, const void*, AVL_CMP));
137 LDAP_AVL_F( Avlnode* )
138 tavl_find3 LDAP_P((Avlnode *, const void*, AVL_CMP, int *ret));
140 #define TAVL_DIR_LEFT 0
141 #define TAVL_DIR_RIGHT 1
143 LDAP_AVL_F( Avlnode* )
144 tavl_end LDAP_P((Avlnode *, int direction ));
146 LDAP_AVL_F( Avlnode* )
147 tavl_next LDAP_P((Avlnode *, int direction ));
149 /* apply traversal types */
150 #define AVL_PREORDER 1
151 #define AVL_INORDER 2
152 #define AVL_POSTORDER 3
153 /* what apply returns if it ran out of nodes */
154 #define AVL_NOMORE (-6)
156 LDAP_END_DECL
158 #endif /* _AVL */