implement cx_tree_add_child_node using cx_linked_list_add

Sun, 26 Sep 2021 15:43:58 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 26 Sep 2021 15:43:58 +0200
changeset 431
dcf01bb852f4
parent 430
d4d643def2ac
child 432
32679add2a2b

implement cx_tree_add_child_node using cx_linked_list_add

src/tree.c file | annotate | diff | comparison | revisions
--- a/src/tree.c	Sun Sep 26 15:43:41 2021 +0200
+++ b/src/tree.c	Sun Sep 26 15:43:58 2021 +0200
@@ -27,6 +27,7 @@
  */
 
 #include "cx/tree.h"
+#include "cx/linked_list.h"
 
 #define CX_TR_PTR(cur, off) ((void**)(((char*)cur)+off))
 
@@ -66,5 +67,12 @@
         void **children_end,
         void *new_node)
 {
-    return 1;
+    if(cx_linked_list_add(children_begin, children_end, loc_prev, loc_next, new_node)) {
+        return 1;
+    }
+    // optional field
+    if(loc_parent >= 0) {
+        *CX_TR_PTR(new_node, loc_parent) = parent;
+    }
+    return 0;
 }

mercurial