From: Benjamin Auder Date: Thu, 4 Feb 2021 21:51:15 +0000 (+0100) Subject: [Tree] add_child and add_sibling now return inserted node. Remove unused H_FILES... X-Git-Url: https://git.auder.net/variants/img/pieces/%7B%7B%20asset%28%27mixstore/doc/%7B%7B?a=commitdiff_plain;h=7820a2aacdb1af3d8d7f4b443b6163517d5f90fe;p=cgds.git [Tree] add_child and add_sibling now return inserted node. Remove unused H_FILES in Makefile --- diff --git a/src/Makefile b/src/Makefile index d995fd6..261a3f5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,7 +9,6 @@ OBJ_DIR = ./obj TARGET = $(OBJ_DIR)/libcgds.so SRC_FILES = $(wildcard $(SRC_DIR)/*.c) -H_FILES = $(wildcard $(SRC_DIR)/*.h) OBJ_FILES = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC_FILES)) all: $(TARGET) diff --git a/src/Tree.c b/src/Tree.c index 83262c4..f9d989d 100644 --- a/src/Tree.c +++ b/src/Tree.c @@ -149,7 +149,7 @@ void _tree_set(Tree* tree, TreeNode* treeNode, void* data) memcpy(treeNode->data, data, tree->dataSize); } -void _tree_add_child(Tree* tree, TreeNode* treeNode, void* data) +TreeNode* _tree_add_child(Tree* tree, TreeNode* treeNode, void* data) { TreeNode* newChildNode = (TreeNode*) safe_malloc(sizeof (TreeNode)); newChildNode->data = safe_malloc(tree->dataSize); @@ -165,9 +165,10 @@ void _tree_add_child(Tree* tree, TreeNode* treeNode, void* data) newChildNode->firstChild = NULL; newChildNode->lastChild = NULL; tree->size++; + return newChildNode; } -void _tree_add_sibling(Tree* tree, TreeNode* treeNode, void* data) +TreeNode* _tree_add_sibling(Tree* tree, TreeNode* treeNode, void* data) { TreeNode* newSiblingNode = (TreeNode*) safe_malloc(sizeof (TreeNode)); newSiblingNode->data = safe_malloc(tree->dataSize); @@ -181,6 +182,7 @@ void _tree_add_sibling(Tree* tree, TreeNode* treeNode, void* data) newSiblingNode->firstChild = NULL; newSiblingNode->lastChild = NULL; tree->size++; + return newSiblingNode; } void _tree_remove_rekursiv(Tree* tree, TreeNode* treeNode) diff --git a/src/Tree.h b/src/Tree.h index a997525..4d20741 100644 --- a/src/Tree.h +++ b/src/Tree.h @@ -166,9 +166,9 @@ void _tree_set( } /** - * @brief Add a child to current node children. + * @brief Append a child to current node. */ -void _tree_add_child( +TreeNode* _tree_add_child( Tree* tree, ///< "this" pointer. TreeNode* treeNode, ///< Pointer to a node in the "this" tree. void* data ///< Pointer to data to be added. @@ -179,8 +179,9 @@ void _tree_add_child( * @param tree "this" pointer. * @param treeNode Pointer to a node in the "this" tree. * @param data Data to be added. + * @return The newly added tree node. * - * Usage: void tree_add_child(Tree* tree, TreeNode* treeNode, void data) + * Usage: TreeNode* tree_add_child(Tree* tree, TreeNode* treeNode, void data) */ #define tree_add_child(tree,treeNode,data) \ { \ @@ -191,7 +192,7 @@ void _tree_add_child( /** * @brief Add a sibling to current node (after it on the right). */ -void _tree_add_sibling( +TreeNode* _tree_add_sibling( Tree* tree, ///< "this" pointer. TreeNode* treeNode, ///< Pointer to a node in the "this" tree. void* data ///< Pointer to data to be added. @@ -202,8 +203,9 @@ void _tree_add_sibling( * @param tree "this" pointer. * @param treeNode Pointer to a node in the "this" tree. * @param data Data to be added. + * @return The newly added tree node. * - * Usage: void tree_add_sibling(Tree* tree, TreeNode* treeNode, void data) + * Usage: TreeNode* tree_add_sibling(Tree* tree, TreeNode* treeNode, void data) */ #define tree_add_sibling(tree, treeNode, data) \ { \ diff --git a/test/t.Tree.c b/test/t.Tree.c index 8cb7157..ed48951 100644 --- a/test/t.Tree.c +++ b/test/t.Tree.c @@ -98,6 +98,7 @@ void t_tree_iterate() lu_assert_int_eq(a, i); treeI_move_next(ti); } + lu_assert(!treeI_has_data(ti)); treeI_destroy(ti); tree_destroy(t);