diff options
Diffstat (limited to 'libdimension/kD_splay_tree.c')
-rw-r--r-- | libdimension/kD_splay_tree.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/libdimension/kD_splay_tree.c b/libdimension/kD_splay_tree.c index de70edf..a661602 100644 --- a/libdimension/kD_splay_tree.c +++ b/libdimension/kD_splay_tree.c @@ -29,10 +29,11 @@ dmnsn_kD_splay_tree * dmnsn_new_kD_splay_tree() { dmnsn_kD_splay_tree *tree = malloc(sizeof(dmnsn_kD_splay_tree)); - if (!tree) { + if (tree) { + tree->root = NULL; + } else { dmnsn_error(DMNSN_SEVERITY_HIGH, "kD splay tree allocation failed."); } - tree->root = NULL; return tree; } @@ -67,20 +68,25 @@ dmnsn_kD_splay_copy(dmnsn_kD_splay_tree *tree) /* Recursively free a kD splay tree */ void -dmnsn_delete_kD_splay_tree(dmnsn_kD_splay_tree *tree) +dmnsn_delete_kD_splay_tree_recursive(dmnsn_kD_splay_node *node) { - dmnsn_kD_splay_node *node = tree->root; if (node) { - tree->root = node->contains; - dmnsn_delete_kD_splay_tree(tree); - - tree->root = node->container; - dmnsn_delete_kD_splay_tree(tree); - + dmnsn_delete_kD_splay_tree_recursive(node->contains); + dmnsn_delete_kD_splay_tree_recursive(node->container); dmnsn_delete_kD_splay_node(node); } } +/* Free a kD splay tree */ +void +dmnsn_delete_kD_splay_tree(dmnsn_kD_splay_tree *tree) +{ + if (tree) { + dmnsn_delete_kD_splay_tree_recursive(tree->root); + free(tree); + } +} + /* Return whether node1 contains node2 */ static int dmnsn_box_contains(dmnsn_vector p, dmnsn_vector min, dmnsn_vector max); |