Not working

FossilOrigin-Name: 73555ad5806080ecc98daade01858676f5d234a13712640a7f3267010b4bd1a9
This commit is contained in:
7u83@mail.ru 2018-03-09 20:27:46 +00:00
parent df6ce963ee
commit e4d65ef470
6 changed files with 31 additions and 18 deletions

View File

@ -75,13 +75,15 @@ union mavldata {
};
typedef union mavldata mavldata_t;
/**
* Defines the structure of an AVL Node.
*/
struct mavlnode {
/** Pointer to data, that belongs to the node */
union mavldata data;
/* union mavldata data; */
/** Pointer to left son*/
struct mavlnode *left;
@ -91,6 +93,11 @@ struct mavlnode {
int bal;
};
#define mavlnode_data(node) ((node)+sizeof(struct mavlnode))
#define mavlnode_copy_data(tree,dst,src)\
memcpy(mavlnode_data(dst),mavlnode_data(src),\
(tree)->data_size)
/**
* AVL Tree
*/
@ -117,8 +124,11 @@ typedef struct mavl * mavl_t;
* @defgroup MAVL_FUNCTIONS Functions
* @{
*/
struct mavl *mavl_create(int (*cmp) (const union mavldata *, const union mavldata *),
void (*del) (union mavldata *));
struct mavl *mavl_create(int (*cmp) (const void *, const void *),
void (*del) (void *), size_t data_size);
void mavlnode_destroy(struct mavl *t, struct mavlnode *n);
@ -126,7 +136,7 @@ void mavl_del_all(struct mavl *t);
union mavldata *mavl_del(struct mavl *t, union mavldata *data);
union mavldata *mavl_add(struct mavl *t, union mavldata *data);
union mavldata * mavl_get(struct mavl *t ,union mavldata *data);
struct mavlnode *mavl_get_node(struct mavl *t, union mavldata *data);
struct mavlnode *mavl_get_node(struct mavl *t, void *data);
void * mavl_get_ptr(mavl_t tree, void * search);
void *mavl_add_ptr(mavl_t tree, void *ptr);
@ -188,7 +198,7 @@ union mavldata * mavliter_seek_set(struct mavliter *i);
void mavliter_init(mavliter_t *i, mavl_t t);
union mavldata * mavliter_get(mavliter_t *i);
void * mavliter_get(mavliter_t *i);
extern union mavldata * mavliter_seek(mavliter_t *i,void *d);

View File

@ -30,8 +30,8 @@
* @param del pointer to delete function which is called when an element will be deletet
* @return pointer to an #mavl struct
*/
struct mavl *mavl_create(int (*cmp) (const union mavldata *, const union mavldata *),
void (*del) (union mavldata *))
struct mavl *mavl_create(int (*cmp) (const void *, const void *),
void (*del) (void *), size_t data_size)
{
struct mavl *t = malloc(sizeof(struct mavl));
if (!t)

View File

@ -22,7 +22,7 @@
#include "mavl.h"
struct mavlnode * mavl_get_node(struct mavl *t ,union mavldata *data)
struct mavlnode * mavl_get_node(struct mavl *t ,void *data)
{
struct mavlnode *n = t->root;
while(n){

View File

@ -27,15 +27,17 @@
static void mavlnode_move(mavl_t m,mavl_t t, struct mavlnode *n)
{
struct mavlnode * mn = mavl_get_node(m,&n->data);
struct mavlnode * mn = mavl_get_node(m,mavlnode_data(n));
if (mn) {
if (m->del) {
m->del(&mn->data);
m->del(mavlnode_data(mn));
}
mn->data=n->data;
/*mn->data=n->data;*/
mavlnode_copy_data(m,mn,n);
}
else{
mavl_add(m,&n->data);
/*mavl_add(m,&n->data);*/
mavl_add(m,mavlnode_data(n));
}
free(n);

View File

@ -1,12 +1,13 @@
#include "mavl.h"
union mavldata *mavl_replace(struct mavl *t,union mavldata *data){
union mavldata *mavl_replace(struct mavl *t,void *data){
struct mavlnode * node = mavl_get_node(t,data);
if (node){
if (t->del)
t->del(&node->data);
node->data=*data;
return &node->data;
t->del(node+sizeof(struct mavlnode));
/* node->data=*data;
*/ mavlnode_copy_data(node+sizeof(struct mavlnode), data);
return &node->data;
}
return mavl_add(t,data);
}

View File

@ -5,10 +5,10 @@
* @param i AVL Iterator
* @return element or NULL if not found.
*/
union mavldata * mavliter_get(mavliter_t *i){
void * mavliter_get(mavliter_t *i){
if(!i->cur)
return NULL;
return &i->cur->data;
/*return &i->cur->data; */
}