about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/search/tdestroy.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/search/tdestroy.c b/src/search/tdestroy.c
new file mode 100644
index 00000000..6f430bda
--- /dev/null
+++ b/src/search/tdestroy.c
@@ -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);
+}