1 /* avl.h - avl tree definitions */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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.
31 #include <ldap_cdefs.h>
34 * this structure represents a generic avl tree node.
39 typedef struct avlnode Avlnode;
45 struct avlnode *avl_left;
46 struct avlnode *avl_right;
49 #define NULLAVL ((Avlnode *) NULL)
51 /* balance factor values */
57 #define avl_getone(x) ((x) == 0 ? 0 : (x)->avl_data)
58 #define avl_onenode(x) ((x) == 0 || ((x)->avl_left == 0 && (x)->avl_right == 0))
60 #endif /* AVL_INTERNALS */
62 typedef int (*AVL_APPLY) LDAP_P((void *, void*));
63 typedef int (*AVL_CMP) LDAP_P((const void*, const void*));
64 typedef int (*AVL_DUP) LDAP_P((void*, void*));
65 typedef void (*AVL_FREE) LDAP_P((void*));
68 avl_free LDAP_P(( Avlnode *root, AVL_FREE dfree ));
71 avl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP));
74 avl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
77 avl_find LDAP_P((Avlnode *, const void*, AVL_CMP));
80 avl_find_lin LDAP_P((Avlnode *, const void*, AVL_CMP));
82 #ifdef AVL_NONREENTRANT
84 avl_getfirst LDAP_P((Avlnode *));
87 avl_getnext LDAP_P((void));
91 avl_dup_error LDAP_P((void*, void*));
94 avl_dup_ok LDAP_P((void*, void*));
97 avl_apply LDAP_P((Avlnode *, AVL_APPLY, void*, int, int));
100 avl_prefixapply LDAP_P((Avlnode *, void*, AVL_CMP, void*, AVL_CMP, void*, int));
102 /* apply traversal types */
103 #define AVL_PREORDER 1
104 #define AVL_INORDER 2
105 #define AVL_POSTORDER 3
106 /* what apply returns if it ran out of nodes */
107 #define AVL_NOMORE (-6)