[Tree] add_child and add_sibling now return inserted node. Remove unused H_FILES...
authorBenjamin Auder <benjamin.auder@somewhere>
Thu, 4 Feb 2021 21:51:15 +0000 (22:51 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Thu, 4 Feb 2021 21:51:15 +0000 (22:51 +0100)
src/Makefile
src/Tree.c
src/Tree.h
test/t.Tree.c

index d995fd6..261a3f5 100644 (file)
@@ -9,7 +9,6 @@ OBJ_DIR = ./obj
 TARGET = $(OBJ_DIR)/libcgds.so
 
 SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
 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)
 OBJ_FILES = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC_FILES))
 
 all: $(TARGET)
index 83262c4..f9d989d 100644 (file)
@@ -149,7 +149,7 @@ void _tree_set(Tree* tree, TreeNode* treeNode, void* data)
   memcpy(treeNode->data, data, tree->dataSize);
 }
 
   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);
 {
   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++;
   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);
 {
   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++;
   newSiblingNode->firstChild = NULL;
   newSiblingNode->lastChild = NULL;
   tree->size++;
+  return newSiblingNode;
 }
 
 void _tree_remove_rekursiv(Tree* tree, TreeNode* treeNode)
 }
 
 void _tree_remove_rekursiv(Tree* tree, TreeNode* treeNode)
index a997525..4d20741 100644 (file)
@@ -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.
   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.
  * @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) \
 { \
  */
 #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).
  */
 /**
  * @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.
   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.
  * @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) \
 { \
  */
 #define tree_add_sibling(tree, treeNode, data) \
 { \
index 8cb7157..ed48951 100644 (file)
@@ -98,6 +98,7 @@ void t_tree_iterate()
     lu_assert_int_eq(a, i);
     treeI_move_next(ti);
   }
     lu_assert_int_eq(a, i);
     treeI_move_next(ti);
   }
+  lu_assert(!treeI_has_data(ti));
 
   treeI_destroy(ti);
   tree_destroy(t);
 
   treeI_destroy(ti);
   tree_destroy(t);