search: add tdestroy (gnu extension)

This commit is contained in:
nsz 2012-05-13 01:34:20 +02:00
parent b47fdcdef8
commit d197d6421c
2 changed files with 23 additions and 0 deletions

View file

@ -38,6 +38,8 @@ struct qelem {
struct qelem *q_forw, *q_back;
char q_data[1];
};
void tdestroy(void *, void (*)(void *));
#endif
#ifdef __cplusplus

21
src/search/tdestroy.c Normal file
View file

@ -0,0 +1,21 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <search.h>
struct node {
void *key;
struct node *left;
struct node *right;
};
void tdestroy(void *root, void (*freekey)(void *))
{
struct node *r = root;
if (r == 0)
return;
tdestroy(r->left, freekey);
tdestroy(r->right, freekey);
freekey(r->key);
free(r);
}