2018-03-21 20:02:25 +01:00
|
|
|
#include "ktv.h"
|
|
|
|
|
2018-03-24 07:56:05 +01:00
|
|
|
void * ktvn(struct mavl *t ,const void *search)
|
|
|
|
{
|
|
|
|
|
2018-03-25 10:35:53 +02:00
|
|
|
struct mavlnode *n,/**lastl,*/*lastb;
|
|
|
|
lastb = NULL; /*lastl=NULL;*/
|
2018-03-24 07:56:05 +01:00
|
|
|
n = t->root;
|
|
|
|
while(n){
|
|
|
|
int rc;
|
2018-03-25 10:35:53 +02:00
|
|
|
/* const cw_KTV_t;*//* *c1,*c2;*/
|
|
|
|
/*c1=search;
|
2018-03-24 07:56:05 +01:00
|
|
|
c2=mavlnode_dataptr(n);
|
2018-03-25 10:35:53 +02:00
|
|
|
*/
|
2018-03-24 07:56:05 +01:00
|
|
|
|
|
|
|
rc = t->cmp(search,mavlnode_dataptr(n));
|
|
|
|
|
|
|
|
/*printf("Compare: %s %s = %d\n",c1->key,c2->key, rc);*/
|
|
|
|
|
|
|
|
if (rc==0){
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc<0){
|
2018-03-25 10:35:53 +02:00
|
|
|
/*lastl = n;*/
|
2018-03-24 07:56:05 +01:00
|
|
|
if (n->left==NULL){
|
|
|
|
return mavlnode_dataptr(lastb);
|
|
|
|
|
|
|
|
}
|
|
|
|
n=n->left;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
lastb=n;
|
|
|
|
if(n->right==NULL){
|
|
|
|
return mavlnode_dataptr(lastb);
|
|
|
|
|
|
|
|
}
|
|
|
|
n=n->right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cw_ktv_idx_get(mavl_t ktv, const char *key, int idx, const cw_Type_t * type)
|
2018-03-21 20:02:25 +01:00
|
|
|
{
|
|
|
|
char ikey[CW_KTV_MAX_KEY_LEN];
|
2018-03-24 07:56:05 +01:00
|
|
|
cw_KTV_t search, * result;
|
|
|
|
char *d;
|
|
|
|
|
|
|
|
sprintf(ikey,"%s.%d",key,65536);
|
|
|
|
|
|
|
|
search.key=ikey;
|
|
|
|
result = ktvn(ktv,&search);
|
|
|
|
|
|
|
|
if (result == NULL){
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
d = strchr(result->key,'.');
|
|
|
|
if (d==NULL){
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(result->key,ikey,d-result->key)!=0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return atoi(d+1);
|
2018-03-21 20:02:25 +01:00
|
|
|
}
|