AVL tree for integers.
FossilOrigin-Name: b926f87dd33cb30a70707ab86240f429c60a12d635e650bc1ab0d0702de075ca
This commit is contained in:
35
src/capwap/intavltree.c
Normal file
35
src/capwap/intavltree.c
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "intavltree.h"
|
||||
|
||||
|
||||
static int cmp(const void *v1,const void*v2)
|
||||
{
|
||||
return *((int*)v1) - *((char*)v2);
|
||||
}
|
||||
|
||||
static void del(void* d)
|
||||
{
|
||||
free (d);
|
||||
return;
|
||||
}
|
||||
|
||||
struct avltree * intavltree_create()
|
||||
{
|
||||
return avltree_create(cmp,del);
|
||||
}
|
||||
|
||||
int * intavltree_add(struct avltree * t, int val)
|
||||
{
|
||||
int *v = avltree_get(t,&val);
|
||||
if (v)
|
||||
return v;
|
||||
|
||||
v = malloc(sizeof(int));
|
||||
if (!v)
|
||||
return NULL;
|
||||
*v=val;
|
||||
return avltree_add(t,v);
|
||||
}
|
Reference in New Issue
Block a user