2018-02-28 09:05:45 +01:00
|
|
|
#include "mavl.h"
|
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
void *mavl_replace(struct mavl *t,const void *data, int * replaced){
|
|
|
|
|
|
|
|
int exists;
|
2022-07-18 01:15:17 +02:00
|
|
|
void * add = mavl_insert(t,data,&exists);
|
2018-03-11 00:56:41 +01:00
|
|
|
|
|
|
|
if (replaced != NULL){
|
|
|
|
*replaced = exists;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!exists){
|
|
|
|
return add;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(t->del){
|
|
|
|
t->del(add);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(add,data,t->data_size);
|
|
|
|
return add;
|
|
|
|
|
|
|
|
/*
|
2018-02-28 09:05:45 +01:00
|
|
|
struct mavlnode * node = mavl_get_node(t,data);
|
|
|
|
if (node){
|
2018-03-06 03:08:14 +01:00
|
|
|
if (t->del)
|
2018-03-09 21:27:46 +01:00
|
|
|
t->del(node+sizeof(struct mavlnode));
|
2018-03-11 00:56:41 +01:00
|
|
|
// node->data=*data;
|
|
|
|
memcpy(mavlnode_dataptr(node), data, t->data_size);
|
|
|
|
|
|
|
|
// return &node->data;
|
|
|
|
return mavlnode_dataptr(node);
|
2018-02-28 09:05:45 +01:00
|
|
|
}
|
2022-07-18 01:15:17 +02:00
|
|
|
return mavl_insert(t,data);
|
2018-03-11 00:56:41 +01:00
|
|
|
*/
|
2018-02-28 09:05:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|