cw_kvstore_add works now

fixed a bug in mavl_add

FossilOrigin-Name: 4b040305182ef40f6f053fe1d84ea15f533e931c9d665b513b9a644592519f3e
This commit is contained in:
7u83@mail.ru
2018-03-07 09:30:40 +00:00
parent 2055a0d644
commit c93867811a
13 changed files with 108 additions and 38 deletions

View File

@ -1,6 +1,5 @@
#include "mavl.h"
static struct mavlnode *mavlnode_create(union mavldata *data)
{
struct mavlnode *n = malloc(sizeof(struct mavlnode));
@ -16,16 +15,16 @@ static struct mavlnode *mavlnode_create(union mavldata *data)
static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata * data)
static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata ** data)
{
struct mavlnode *tmp;
struct mavlnode *n = *parent;
int rc = t->cmp(data, &n->data);
int rc = t->cmp(*data, &n->data);
int bal;
if (rc == 0) {
*data = n->data;
*data = &n->data;
return 2;
}
@ -78,7 +77,7 @@ static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata *
}
/* n->left is 0 */
n->left = mavlnode_create(data);
n->left = mavlnode_create(*data);
if (!n->left)
return 3;
@ -141,7 +140,7 @@ static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata *
/* n->right is 0 */
n->right = mavlnode_create(data);
n->right = mavlnode_create(*data);
if (!n->right)
return 3;
@ -170,7 +169,7 @@ static int mavl_add0(struct mavl *t, struct mavlnode **parent, union mavldata *
* @example mavl_add_example.c
*/
union mavldata *mavl_add(struct mavl *t, union mavldata *data)
union mavldata *mavl_add(struct mavl *t, const union mavldata *data)
{
union mavldata * d;
int rc;
@ -184,7 +183,7 @@ union mavldata *mavl_add(struct mavl *t, union mavldata *data)
d = data;
rc = mavl_add0(t, &t->root, d);
rc = mavl_add0(t, &t->root, &d);
if (rc > 3)
return NULL;