3 * Copyright 1998-2002 The OpenLDAP Foundation, Redwood City, California, USA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted only as authorized by the OpenLDAP
8 * Public License. A copy of this license is available at
9 * http://www.OpenLDAP.org/license.html or in file LICENSE in the
10 * top-level directory of the distribution.
13 * Copyright (c) 1993 Regents of the University of Michigan.
14 * All rights reserved.
16 * Redistribution and use in source and binary forms are permitted
17 * provided that this notice is preserved and that due credit is given
18 * to the University of Michigan at Ann Arbor. The name of the University
19 * may not be used to endorse or promote products derived from this
20 * software without specific prior written permission. This software
21 * is provided ``as is'' without express or implied warranty.
23 /* avl.h - avl tree definitions */
29 #include <ldap_cdefs.h>
32 * this structure represents a generic avl tree node.
37 typedef struct avlnode Avlnode;
43 struct avlnode *avl_left;
44 struct avlnode *avl_right;
47 #define NULLAVL ((Avlnode *) NULL)
49 /* balance factor values */
55 #define avl_getone(x) ((x) == 0 ? 0 : (x)->avl_data)
56 #define avl_onenode(x) ((x) == 0 || ((x)->avl_left == 0 && (x)->avl_right == 0))
58 #endif /* AVL_INTERNALS */
60 typedef int (*AVL_APPLY) LDAP_P((void *, void*));
61 typedef int (*AVL_CMP) LDAP_P((const void*, const void*));
62 typedef int (*AVL_DUP) LDAP_P((void*, void*));
63 typedef void (*AVL_FREE) LDAP_P((void*));
66 avl_free LDAP_P(( Avlnode *root, AVL_FREE dfree ));
69 avl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP));
72 avl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
75 avl_find LDAP_P((Avlnode *, const void*, AVL_CMP));
78 avl_find_lin LDAP_P((Avlnode *, const void*, AVL_CMP));
80 #ifdef AVL_NONREENTRANT
82 avl_getfirst LDAP_P((Avlnode *));
85 avl_getnext LDAP_P((void));
89 avl_dup_error LDAP_P((void*, void*));
92 avl_dup_ok LDAP_P((void*, void*));
95 avl_apply LDAP_P((Avlnode *, AVL_APPLY, void*, int, int));
98 avl_prefixapply LDAP_P((Avlnode *, void*, AVL_CMP, void*, AVL_CMP, void*, int));
100 /* apply traversal types */
101 #define AVL_PREORDER 1
102 #define AVL_INORDER 2
103 #define AVL_POSTORDER 3
104 /* what apply returns if it ran out of nodes */
105 #define AVL_NOMORE (-6)