#define avl_lbit avl_bits[0]
#define avl_rbit avl_bits[1]
-#ifdef AVL_INTERNAL
+typedef struct tavlnode TAvlnode;
-#define NULLAVL ((Avlnode *) NULL)
+struct tavlnode {
+ void* avl_data;
+ struct tavlnode *avl_link[2];
+ char avl_bits[2];
+ signed char avl_bf;
+};
+
+#ifdef AVL_INTERNAL
/* balance factor values */
#define LH (-1)
#define avl_bf2str(bf) ((bf) == -1 ? "LH" : (bf) == 0 ? "EH" : (bf) == 1 ? "RH" : "(unknown)" )
/* thread bits */
-#define AVL_THREAD 0
-#define AVL_CHILD 1
+#define AVL_CHILD 0
+#define AVL_THREAD 1
/* avl routines */
#define avl_getone(x) ((x) == 0 ? 0 : (x)->avl_data)
avl_prefixapply LDAP_P((Avlnode *, void*, AVL_CMP, void*, AVL_CMP, void*, int));
LDAP_AVL_F( int )
-tavl_free LDAP_P(( Avlnode *root, AVL_FREE dfree ));
+tavl_free LDAP_P(( TAvlnode *root, AVL_FREE dfree ));
LDAP_AVL_F( int )
-tavl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP));
+tavl_insert LDAP_P((TAvlnode **, void*, AVL_CMP, AVL_DUP));
LDAP_AVL_F( void* )
-tavl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
+tavl_delete LDAP_P((TAvlnode **, void*, AVL_CMP));
LDAP_AVL_F( void* )
-tavl_find LDAP_P((Avlnode *, const void*, AVL_CMP));
+tavl_find LDAP_P((TAvlnode *, const void*, AVL_CMP));
-LDAP_AVL_F( Avlnode* )
-tavl_find2 LDAP_P((Avlnode *, const void*, AVL_CMP));
+LDAP_AVL_F( TAvlnode* )
+tavl_find2 LDAP_P((TAvlnode *, const void*, AVL_CMP));
-LDAP_AVL_F( Avlnode* )
-tavl_find3 LDAP_P((Avlnode *, const void*, AVL_CMP, int *ret));
+LDAP_AVL_F( TAvlnode* )
+tavl_find3 LDAP_P((TAvlnode *, const void*, AVL_CMP, int *ret));
#define TAVL_DIR_LEFT 0
#define TAVL_DIR_RIGHT 1
-LDAP_AVL_F( Avlnode* )
-tavl_end LDAP_P((Avlnode *, int direction ));
+LDAP_AVL_F( TAvlnode* )
+tavl_end LDAP_P((TAvlnode *, int direction));
-LDAP_AVL_F( Avlnode* )
-tavl_next LDAP_P((Avlnode *, int direction ));
+LDAP_AVL_F( TAvlnode* )
+tavl_next LDAP_P((TAvlnode *, int direction));
/* apply traversal types */
#define AVL_PREORDER 1
}
r->avl_link[0] = r->avl_link[1] = NULL;
r->avl_data = data;
+ r->avl_bits[0] = r->avl_bits[1] = AVL_CHILD;
r->avl_bf = EH;
*root = r;
}
q->avl_link[0] = q->avl_link[1] = NULL;
q->avl_data = data;
+ q->avl_bits[0] = q->avl_bits[1] = AVL_CHILD;
q->avl_bf = EH;
p->avl_link[cmp] = q;
* NOTE: this routine may malloc memory
*/
int
-tavl_insert( Avlnode ** root, void *data, AVL_CMP fcmp, AVL_DUP fdup )
+tavl_insert( TAvlnode ** root, void *data, AVL_CMP fcmp, AVL_DUP fdup )
{
- Avlnode *t, *p, *s, *q, *r;
+ TAvlnode *t, *p, *s, *q, *r;
int a, cmp, ncmp;
if ( *root == NULL ) {
- if (( r = (Avlnode *) ber_memalloc( sizeof( Avlnode ))) == NULL ) {
+ if (( r = (TAvlnode *) ber_memalloc( sizeof( TAvlnode ))) == NULL ) {
return( -1 );
}
r->avl_link[0] = r->avl_link[1] = NULL;
q = avl_child( p, cmp );
if (q == NULL) {
/* insert */
- if (( q = (Avlnode *) ber_memalloc( sizeof( Avlnode ))) == NULL ) {
+ if (( q = (TAvlnode *) ber_memalloc( sizeof( TAvlnode ))) == NULL ) {
return( -1 );
}
q->avl_link[cmp] = p->avl_link[cmp];
}
void*
-tavl_delete( Avlnode **root, void* data, AVL_CMP fcmp )
+tavl_delete( TAvlnode **root, void* data, AVL_CMP fcmp )
{
- Avlnode *p, *q, *r, *top;
+ TAvlnode *p, *q, *r, *top;
int side, side_bf, shorter, nside = -1;
/* parent stack */
- Avlnode *pptr[MAX_TREE_DEPTH];
+ TAvlnode *pptr[MAX_TREE_DEPTH];
unsigned char pdir[MAX_TREE_DEPTH];
int depth = 0;
*/
int
-tavl_free( Avlnode *root, AVL_FREE dfree )
+tavl_free( TAvlnode *root, AVL_FREE dfree )
{
int nleft, nright;
*/
/*
- * tavl_find2 - returns Avlnode instead of data pointer.
- * tavl_find3 - as above, but returns Avlnode even if no match is found.
+ * tavl_find2 - returns TAvlnode instead of data pointer.
+ * tavl_find3 - as above, but returns TAvlnode even if no match is found.
* also set *ret = last comparison result, or -1 if root == NULL.
*/
-Avlnode *
-tavl_find3( Avlnode *root, const void *data, AVL_CMP fcmp, int *ret )
+TAvlnode *
+tavl_find3( TAvlnode *root, const void *data, AVL_CMP fcmp, int *ret )
{
int cmp = -1, dir;
- Avlnode *prev = root;
+ TAvlnode *prev = root;
while ( root != 0 && (cmp = (*fcmp)( data, root->avl_data )) != 0 ) {
prev = root;
return root ? root : prev;
}
-Avlnode *
-tavl_find2( Avlnode *root, const void *data, AVL_CMP fcmp )
+TAvlnode *
+tavl_find2( TAvlnode *root, const void *data, AVL_CMP fcmp )
{
int cmp;
}
void*
-tavl_find( Avlnode *root, const void* data, AVL_CMP fcmp )
+tavl_find( TAvlnode *root, const void* data, AVL_CMP fcmp )
{
int cmp;
}
/* Return the leftmost or rightmost node in the tree */
-Avlnode *
-tavl_end( Avlnode *root, int dir )
+TAvlnode *
+tavl_end( TAvlnode *root, int dir )
{
if ( root ) {
while ( root->avl_bits[dir] == AVL_CHILD )
}
/* Return the next node in the given direction */
-Avlnode *
-tavl_next( Avlnode *root, int dir )
+TAvlnode *
+tavl_next( TAvlnode *root, int dir )
{
if ( root ) {
int c = root->avl_bits[dir];
#define AVL_INTERNAL
#include "avl.h"
-static void ravl_print LDAP_P(( Avlnode *root, int depth, int thread ));
-static void myprint LDAP_P(( Avlnode *root ));
+static void ravl_print LDAP_P(( TAvlnode *root, int depth, int thread ));
+static void myprint LDAP_P(( TAvlnode *root ));
static int avl_strcmp LDAP_P(( const void *s, const void *t ));
int
main( int argc, char **argv )
{
- Avlnode *tree = NULL, *n;
+ TAvlnode *tree = NULL, *n;
char command[ 10 ];
char name[ 80 ];
char *p;
static const char bfc_array[] = "\\-/";
static const char *bfcs = bfc_array+1;
-static void ravl_print( Avlnode *root, int depth, int thread )
+static void ravl_print( TAvlnode *root, int depth, int thread )
{
int i;
ravl_print( root->avl_link[0], depth+1, root->avl_bits[0] == AVL_THREAD );
}
-static void myprint( Avlnode *root )
+static void myprint( TAvlnode *root )
{
printf( "********\n" );
#ifdef LDAP_COMP_MATCH
ComponentReference* ai_cr; /*component indexing*/
#endif
- Avlnode *ai_root; /* for tools */
+ TAvlnode *ai_root; /* for tools */
MDB_cursor *ai_cursor; /* for tools */
int ai_idx; /* position in AI array */
MDB_dbi ai_dbi;
dbi = ai->ai_dbi;
for (i=0; keys[i].bv_val; i++) {
itmp.kstr = keys[i];
- ic = tavl_find( (Avlnode *)ai->ai_root, &itmp, mdb_tool_idl_cmp );
+ ic = tavl_find( ai->ai_root, &itmp, mdb_tool_idl_cmp );
/* No entry yet, create one */
if ( !ic ) {
ic->count = 0;
ic->offset = 0;
ic->flags = 0;
- tavl_insert( (Avlnode **)&ai->ai_root, ic, mdb_tool_idl_cmp,
+ tavl_insert( &ai->ai_root, ic, mdb_tool_idl_cmp,
avl_dup_error );
/* load existing key count here */
struct query_template_s;
typedef struct Qbase_s {
- Avlnode *scopes[4]; /* threaded AVL trees of cached queries */
+ TAvlnode *scopes[4]; /* threaded AVL trees of cached queries */
struct berval base;
int queries;
} Qbase;
} fstack;
static CachedQuery *
-find_filter( Operation *op, Avlnode *root, Filter *inputf, Filter *first )
+find_filter( Operation *op, TAvlnode *root, Filter *inputf, Filter *first )
{
Filter* fs;
Filter* fi;
MatchingRule* mrule = NULL;
int res=0, eqpass= 0;
int ret, rc, dir;
- Avlnode *ptr;
+ TAvlnode *ptr;
CachedQuery cq, *qc;
fstack *stack = NULL, *fsp;
typedef struct sort_op
{
- Avlnode *so_tree;
+ TAvlnode *so_tree;
sort_ctrl *so_ctrl;
sssvlv_info *so_info;
int so_paged;
int sess_id;
if ( so->so_tree ) {
if ( so->so_paged > SLAP_CONTROL_IGNORED ) {
- Avlnode *cur_node, *next_node;
+ TAvlnode *cur_node, *next_node;
cur_node = so->so_tree;
while ( cur_node ) {
next_node = tavl_next( cur_node, TAVL_DIR_RIGHT );
SlapReply *rs,
sort_op *so)
{
- Avlnode *cur_node, *tmp_node;
+ TAvlnode *cur_node, *tmp_node;
vlv_ctrl *vc = op->o_controls[vlv_cid];
int i, j, dir, rc;
BackendDB *be;
static void send_page( Operation *op, SlapReply *rs, sort_op *so )
{
- Avlnode *cur_node = so->so_tree;
- Avlnode *next_node = NULL;
+ TAvlnode *cur_node = so->so_tree;
+ TAvlnode *next_node = NULL;
BackendDB *be = op->o_bd;
Entry *e;
int rc;
send_list( op, rs, so );
} else {
/* Get the first node to send */
- Avlnode *start_node = tavl_end(so->so_tree, TAVL_DIR_LEFT);
+ TAvlnode *start_node = tavl_end(so->so_tree, TAVL_DIR_LEFT);
so->so_tree = start_node;
if ( so->so_paged <= SLAP_CONTROL_IGNORED ) {
BackendDB *db;
slap_overinst *on;
Filter *orig;
- Avlnode *list;
+ TAvlnode *list;
int step;
int slimit;
AttributeName *attrs;
/* Send out anything remaining on the list and finish */
if ( tc.step & USE_LIST ) {
if ( tc.list ) {
- Avlnode *av;
+ TAvlnode *av;
av = tavl_end( tc.list, TAVL_DIR_LEFT );
while ( av ) {