Work on discovery cache
FossilOrigin-Name: 42e420b380c09de60f46dc30fcb12a3480f7c6441e438bf45a4066d74369215f
This commit is contained in:
@ -149,6 +149,7 @@ MAVLSRC=\
|
||||
mavl_foreach_lr.c\
|
||||
mavl_freeptr.c\
|
||||
mavl_get.c\
|
||||
mavl_get_ext.c\
|
||||
mavl_get_node.c\
|
||||
mavl_get_node_cmp..c\
|
||||
mavl_get_ptr.c\
|
||||
|
@ -93,7 +93,8 @@ struct mavl {
|
||||
*/
|
||||
typedef struct mavl * mavl_t;
|
||||
|
||||
|
||||
#define MAVL_FIND_FIRST 1
|
||||
#define MAVL_FIND_LAST 2
|
||||
|
||||
/**
|
||||
* @param node node
|
||||
@ -107,6 +108,8 @@ void *mavl_add ( struct mavl *t, const void *data, int *exists );
|
||||
|
||||
/*void *mavl_add ( struct mavl *t, const void *data );*/
|
||||
void * mavl_get ( struct mavl *t , const void *data );
|
||||
void * mavl_get_ext(struct mavl *t ,const void *search, int mode);
|
||||
|
||||
void *mavl_del ( struct mavl *t, const void *data );
|
||||
void *mavl_replace ( struct mavl *t, const void *data, int * result );
|
||||
void mavl_destroy ( struct mavl *t );
|
||||
@ -118,8 +121,8 @@ struct mavlnode * mavl_get_node_cmp(struct mavl *t ,void *data,
|
||||
int ( *cmp ) ( const void *, const void * ));
|
||||
|
||||
|
||||
|
||||
|
||||
#define mavl_get_first(tree,search) mavl_get_ext(tree,search,MAVL_FIND_FIRST)
|
||||
#define mavl_get_last(tree,search) mavl_get_ext(tree,search,MAVL_FIND_LAST)
|
||||
|
||||
|
||||
|
||||
|
49
src/cw/mavl_get_ext.c
Normal file
49
src/cw/mavl_get_ext.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include "mavl.h"
|
||||
|
||||
|
||||
|
||||
void * mavl_get_ext(struct mavl *t ,const void *search, int mode)
|
||||
{
|
||||
|
||||
struct mavlnode *n,/**lastl,*/*last;
|
||||
last = NULL; /*lastl=NULL;*/
|
||||
n = t->root;
|
||||
while(n){
|
||||
int rc;
|
||||
|
||||
rc = t->cmp(search,mavlnode_dataptr(n));
|
||||
|
||||
/*printf("Compare: %s %s = %d\n",c1->key,c2->key, rc);*/
|
||||
|
||||
if (rc==0){
|
||||
return mavlnode_dataptr(n);
|
||||
|
||||
}
|
||||
|
||||
if (rc<0){
|
||||
if (mode == MAVL_FIND_FIRST)
|
||||
last = n;
|
||||
if (n->left==NULL){
|
||||
if (last == NULL)
|
||||
return NULL;
|
||||
return mavlnode_dataptr(last);
|
||||
|
||||
}
|
||||
n=n->left;
|
||||
}
|
||||
else{
|
||||
if (mode == MAVL_FIND_LAST)
|
||||
last=n;
|
||||
|
||||
if(n->right==NULL){
|
||||
if (last == NULL)
|
||||
return NULL;
|
||||
return mavlnode_dataptr(last);
|
||||
|
||||
}
|
||||
n=n->right;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user