|
@@ -1,6 +1,7 @@
|
|
|
#include "bitree.h"
|
|
|
#include <mm/slab.h>
|
|
|
#include <common/errno.h>
|
|
|
+#include <common/kfifo.h>
|
|
|
#include <debug/bug.h>
|
|
|
|
|
|
#define smaller(root, a, b) (root->cmp((a)->value, (b)->value) == -1)
|
|
@@ -201,6 +202,34 @@ int bt_delete(struct bt_root_t *root, void *value)
|
|
|
*/
|
|
|
int bt_destroy_tree(struct bt_root_t *root)
|
|
|
{
|
|
|
-
|
|
|
- return -1;
|
|
|
+
|
|
|
+
|
|
|
+ struct kfifo_t fifo;
|
|
|
+ kfifo_alloc(&fifo, ((root->size + 1) / 2) * sizeof(struct bt_node_t *), 0);
|
|
|
+ kfifo_in(&fifo, (void *)&(root->bt_node), sizeof(struct bt_node_t *));
|
|
|
+
|
|
|
+
|
|
|
+ while (!kfifo_empty(&fifo))
|
|
|
+ {
|
|
|
+
|
|
|
+ struct bt_node_t *nd;
|
|
|
+ uint64_t res;
|
|
|
+ int count = kfifo_out(&fifo, &res, sizeof(uint64_t));
|
|
|
+ nd = (struct bt_node_t *)res;
|
|
|
+
|
|
|
+
|
|
|
+ if (nd->left != NULL)
|
|
|
+ kfifo_in(&fifo, (void *)&(nd->left), sizeof(struct bt_node_t *));
|
|
|
+
|
|
|
+ if (nd->right != NULL)
|
|
|
+ kfifo_in(&fifo, (void *)&(nd->right), sizeof(struct bt_node_t *));
|
|
|
+
|
|
|
+
|
|
|
+ root->release(nd->value);
|
|
|
+ kfree(nd);
|
|
|
+ }
|
|
|
+
|
|
|
+ kfifo_free_alloc(&fifo);
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|