FossilOrigin-Name: 8e68ed51a2c8ee448474ab13ef8d0edbd8cfda5b5384684e2ed9ffa1fca4e799bsdmakefiles
parent
a9bb2d523c
commit
257f1189b0
@ -1,3 +0,0 @@ |
||||
#include "ktv.h" |
||||
#include "dbg.h" |
||||
|
@ -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); |
||||
} |
||||
|
@ -0,0 +1,12 @@ |
||||
#include "lw.h" |
||||
|
||||
/**
|
||||
* Put a #bstr_t to an output buffer |
||||
* @param dst Destination
|
||||
* @param b bstr to put |
||||
* @return The number of bytes put |
||||
*/ |
||||
int lw_put_bstr(uint8_t * dst, const bstr_t b){ |
||||
lw_put_data(dst,bstr_data(b),bstr_len(b)); |
||||
return bstr_len(b); |
||||
} |
@ -0,0 +1,18 @@ |
||||
|
||||
#include "mavl.h" |
||||
|
||||
struct mavlnode * mavl_get_node_cmp(struct mavl *t ,void *data, |
||||
int ( *cmp ) ( const void *, const void * )) |
||||
{ |
||||
struct mavlnode *n = t->root; |
||||
while(n){ |
||||
int rc=cmp(data,mavlnode_dataptr(n)); |
||||
if (rc==0) |
||||
return n; |
||||
if (rc<0) |
||||
n=n->left; |
||||
else |
||||
n=n->right; |
||||
} |
||||
return NULL; |
||||
} |
Loading…
Reference in new issue