about summary refs log tree commit diff
path: root/src/search/tdestroy.c
blob: 699a901c6a8e628a5465c82a7b48837139d4b751 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#define _GNU_SOURCE
#include <stdlib.h>
#include <search.h>
#include "tsearch.h"

void tdestroy(void *root, void (*freekey)(void *))
{
	struct node *r = root;

	if (r == 0)
		return;
	tdestroy(r->a[0], freekey);
	tdestroy(r->a[1], freekey);
	if (freekey) freekey((void *)r->key);
	free(r);
}