ac descriptor works
FossilOrigin-Name: 8e68ed51a2c8ee448474ab13ef8d0edbd8cfda5b5384684e2ed9ffa1fca4e799
This commit is contained in:
@ -1,8 +1,73 @@
|
||||
#include "ktv.h"
|
||||
|
||||
cw_KTV_t * cw_ktv_idx_get(mavl_t ktv, const char *key, int idx, const cw_Type_t * type)
|
||||
void * ktvn(struct mavl *t ,const void *search)
|
||||
{
|
||||
|
||||
struct mavlnode *n,*lastl,*lastb;
|
||||
lastb = NULL; lastl=NULL;
|
||||
n = t->root;
|
||||
while(n){
|
||||
int rc;
|
||||
const cw_KTV_t *c1,*c2;
|
||||
c1=search;
|
||||
c2=mavlnode_dataptr(n);
|
||||
|
||||
|
||||
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){
|
||||
lastl = n;
|
||||
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)
|
||||
{
|
||||
char ikey[CW_KTV_MAX_KEY_LEN];
|
||||
sprintf(ikey,"%s.%d",key,idx);
|
||||
return cw_ktv_get(ktv,ikey,type);
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user