diff --git a/src/capwap/intavltree.c b/src/capwap/intavltree.c new file mode 100644 index 00000000..d060bf9a --- /dev/null +++ b/src/capwap/intavltree.c @@ -0,0 +1,35 @@ + + +#include + +#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); +} diff --git a/src/capwap/intavltree.h b/src/capwap/intavltree.h new file mode 100644 index 00000000..3b53bae5 --- /dev/null +++ b/src/capwap/intavltree.h @@ -0,0 +1,14 @@ +#ifndef __INTAVLTREE_H +#define __INTAVLTREE_H + +#include "avltree.h" + +extern struct avltree * intavltree_create(); +int * intavltree_add(struct avltree * t, int val); + +#define intavltree_destroy(t) avltree_destroy(t) +#define intavltree_foreach_asc(t,f,p) avltree_foreach_asc(t,f,p) +#define intavltree_foreach_desc(t,f,p) avltree_foreach_desc(t,f,p) + + +#endif