merge changes from default branch feature/tree_add

Sat, 17 Aug 2024 11:14:39 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 17 Aug 2024 11:14:39 +0200
branch
feature/tree_add
changeset 863
4a220afebad0
parent 860
558ed4c6abd0 (diff)
parent 862
387414a7afd8 (current diff)
child 864
7d3061f212cb

merge changes from default branch

src/cx/tree.h file | annotate | diff | comparison | revisions
src/tree.c file | annotate | diff | comparison | revisions
--- a/src/cx/tree.h	Sun Jul 07 14:56:44 2024 +0200
+++ b/src/cx/tree.h	Sat Aug 17 11:14:39 2024 +0200
@@ -410,6 +410,49 @@
         ptrdiff_t loc_next
 );
 
+/**
+ * Describes a function that creates a tree node from the specified data.
+ */
+typedef void (*cx_tree_node_create_fun)(void const*);
+
+__attribute__((__nonnull__))
+size_t cx_tree_add_iter(
+        struct cx_iterator_base_s *iter,
+        cx_tree_search_func sfunc,
+        cx_tree_node_create_fun cfunc,
+        void **root,
+        ptrdiff_t loc_parent,
+        ptrdiff_t loc_children,
+        ptrdiff_t loc_prev,
+        ptrdiff_t loc_next
+);
+
+__attribute__((__nonnull__))
+size_t cx_tree_add_array(
+        void const *src,
+        size_t num,
+        size_t elem_size,
+        cx_tree_search_func sfunc,
+        cx_tree_node_create_fun cfunc,
+        void **root,
+        ptrdiff_t loc_parent,
+        ptrdiff_t loc_children,
+        ptrdiff_t loc_prev,
+        ptrdiff_t loc_next
+);
+
+__attribute__((__nonnull__))
+void *cx_tree_add(
+        void const *src,
+        cx_tree_search_func sfunc,
+        cx_tree_node_create_fun cfunc,
+        void **root,
+        ptrdiff_t loc_parent,
+        ptrdiff_t loc_children,
+        ptrdiff_t loc_prev,
+        ptrdiff_t loc_next
+);
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
--- a/src/tree.c	Sun Jul 07 14:56:44 2024 +0200
+++ b/src/tree.c	Sat Aug 17 11:14:39 2024 +0200
@@ -426,3 +426,65 @@
     return iter;
 }
 
+void *cx_tree_add(
+        void const *src,
+        cx_tree_search_func sfunc,
+        cx_tree_node_create_fun cfunc,
+        void **root,
+        ptrdiff_t loc_parent,
+        ptrdiff_t loc_children,
+        ptrdiff_t loc_prev,
+        ptrdiff_t loc_next
+) {
+    // TODO: implement
+    return NULL;
+}
+
+size_t cx_tree_add_iter(
+        struct cx_iterator_base_s *iter,
+        cx_tree_search_func sfunc,
+        cx_tree_node_create_fun cfunc,
+        void **root,
+        ptrdiff_t loc_parent,
+        ptrdiff_t loc_children,
+        ptrdiff_t loc_prev,
+        ptrdiff_t loc_next
+) {
+    // TODO: implement
+    return 0;
+}
+
+size_t cx_tree_add_array(
+        void const *src,
+        size_t num,
+        size_t elem_size,
+        cx_tree_search_func sfunc,
+        cx_tree_node_create_fun cfunc,
+        void **root,
+        ptrdiff_t loc_parent,
+        ptrdiff_t loc_children,
+        ptrdiff_t loc_prev,
+        ptrdiff_t loc_next
+) {
+    // super special case: zero elements
+    if (num == 0) {
+        return 0;
+    }
+
+    // special case: one element does not need an iterator
+    if (num == 1) {
+        if (NULL != cx_tree_add(
+                src, sfunc, cfunc, root,
+                loc_parent, loc_children, loc_prev, loc_next)) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+
+    // otherwise, create iterator and hand over to other function
+    CxIterator iter = cxIterator(src, elem_size, num);
+    return cx_tree_add_iter(cxIteratorRef(iter), sfunc, cfunc, root,
+                            loc_parent, loc_children, loc_prev, loc_next);
+}
+

mercurial