AVL tree for integers.

FossilOrigin-Name: b926f87dd33cb30a70707ab86240f429c60a12d635e650bc1ab0d0702de075ca
This commit is contained in:
7u83@mail.ru 2015-04-05 20:32:12 +00:00
parent 7845fcd781
commit c0985357a1
2 changed files with 49 additions and 0 deletions

35
src/capwap/intavltree.c Normal file
View 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);
}

14
src/capwap/intavltree.h Normal file
View File

@ -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