f4ebe841a5
FossilOrigin-Name: 8a43dd9d05a4cb73210243ddd8df2a26f16c7ef2c4d4e36ab446de1f65d88223
36 lines
439 B
C
36 lines
439 B
C
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "intavltree.h"
|
|
|
|
|
|
static int cmp(const void *v1,const void*v2)
|
|
{
|
|
return *((int*)v1) - *((int*)v2);
|
|
}
|
|
|
|
static void del(void* d)
|
|
{
|
|
free (d);
|
|
return;
|
|
}
|
|
|
|
struct mavl * intavltree_create()
|
|
{
|
|
return mavl_create(cmp,del);
|
|
}
|
|
|
|
int * intavltree_add(struct mavl * t, int val)
|
|
{
|
|
int *v = mavl_get(t,&val);
|
|
if (v)
|
|
return v;
|
|
|
|
v = malloc(sizeof(int));
|
|
if (!v)
|
|
return NULL;
|
|
*v=val;
|
|
return mavl_add(t,v);
|
|
}
|