Add avl_find2 returning the Avlnode, allowing its data to be reset directly

instead of recycling thru avl_find/avl_delete/avl_insert
This commit is contained in:
Howard Chu 2004-11-19 23:33:46 +00:00
parent d7c5ccabe9
commit 9fd1c81713
2 changed files with 14 additions and 3 deletions

View file

@ -38,7 +38,6 @@ LDAP_BEGIN_DECL
typedef struct avlnode Avlnode;
#ifdef AVL_INTERNAL
struct avlnode {
void* avl_data;
signed int avl_bf;
@ -46,6 +45,8 @@ struct avlnode {
struct avlnode *avl_right;
};
#ifdef AVL_INTERNAL
#define NULLAVL ((Avlnode *) NULL)
/* balance factor values */
@ -76,6 +77,9 @@ avl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
LDAP_AVL_F( void* )
avl_find LDAP_P((Avlnode *, const void*, AVL_CMP));
LDAP_AVL_F( Avlnode* )
avl_find2 LDAP_P((Avlnode *, const void*, AVL_CMP));
LDAP_AVL_F( void* )
avl_find_lin LDAP_P((Avlnode *, const void*, AVL_CMP));

View file

@ -644,8 +644,8 @@ avl_free( Avlnode *root, AVL_FREE dfree )
* < 0 if arg1 is less than arg2 and > 0 if arg1 is greater than arg2.
*/
void*
avl_find( Avlnode *root, const void* data, AVL_CMP fcmp )
Avlnode *
avl_find2( Avlnode *root, const void *data, AVL_CMP fcmp )
{
int cmp;
@ -655,6 +655,13 @@ avl_find( Avlnode *root, const void* data, AVL_CMP fcmp )
else
root = root->avl_right;
}
return root;
}
void*
avl_find( Avlnode *root, const void* data, AVL_CMP fcmp )
{
root = avl_find2( root, data, fcmp );
return( root ? root->avl_data : 0 );
}