avl.h 1.91 KB
Newer Older
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* avl.h - avl tree definitions */
/*
 * Copyright (c) 1993 Regents of the University of Michigan.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that this notice is preserved and that due credit is given
 * to the University of Michigan at Ann Arbor. The name of the University
 * may not be used to endorse or promote products derived from this
 * software without specific prior written permission. This software
 * is provided ``as is'' without express or implied warranty.
 */


#ifndef _AVL
#define _AVL

18
19
#include <ldap_cdefs.h>

Kurt Zeilenga's avatar
Kurt Zeilenga committed
20
21
22
23
/*
 * this structure represents a generic avl tree node.
 */

24
25
LDAP_BEGIN_DECL

Kurt Zeilenga's avatar
Kurt Zeilenga committed
26
27
typedef struct avlnode {
	caddr_t		avl_data;
28
	signed char		avl_bf;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
29
30
31
32
33
34
35
	struct avlnode	*avl_left;
	struct avlnode	*avl_right;
} Avlnode;

#define NULLAVL	((Avlnode *) NULL)

/* balance factor values */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
36
#define LH 	(-1)
Kurt Zeilenga's avatar
Kurt Zeilenga committed
37
38
39
40
#define EH 	0
#define RH 	1

/* avl routines */
41
42
43
44
45
46
47
#define avl_getone(x)	((x) == 0 ? 0 : (x)->avl_data)
#define avl_onenode(x)	((x) == 0 || ((x)->avl_left == 0 && (x)->avl_right == 0))

/* looks like this function pointer is not used consistently */
/* typedef int	(*IFP)LDAP_P((caddr_t, caddr_t)); */
typedef int	(*IFP)();

48
49
50
LDAP_F int
avl_free LDAP_P(( Avlnode *root, IFP dfree ));

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
LDAP_F int
avl_insert LDAP_P((Avlnode **, caddr_t, IFP, IFP));

LDAP_F caddr_t
avl_delete LDAP_P((Avlnode **, caddr_t, IFP));

LDAP_F caddr_t
avl_find LDAP_P((Avlnode *, caddr_t, IFP));

LDAP_F caddr_t
avl_getfirst LDAP_P((Avlnode *));

#ifdef AVL_REENTRANT
LDAP_F caddr_t
avl_getnext LDAP_P((Avlnode *, caddr_t ));
#else
LDAP_F caddr_t
avl_getnext LDAP_P((void));
#endif

LDAP_F int
avl_dup_error LDAP_P((void));

LDAP_F int
avl_apply LDAP_P((Avlnode *, IFP, caddr_t, int, int));
Kurt Zeilenga's avatar
Kurt Zeilenga committed
76
77
78
79
80
81

/* apply traversal types */
#define AVL_PREORDER	1
#define AVL_INORDER	2
#define AVL_POSTORDER	3
/* what apply returns if it ran out of nodes */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
82
#define AVL_NOMORE	(-6)
Kurt Zeilenga's avatar
Kurt Zeilenga committed
83

84
85
LDAP_END_DECL

Kurt Zeilenga's avatar
Kurt Zeilenga committed
86
#endif /* _AVL */