add allocator and root node pointer to tree structure

Sun, 29 Sep 2024 22:45:43 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 29 Sep 2024 22:45:43 +0200
changeset 897
0936916856a2
parent 896
7e09c76390c3
child 898
9b2c12494ccf

add allocator and root node pointer to tree structure

relates to #166

src/cx/tree.h file | annotate | diff | comparison | revisions
--- a/src/cx/tree.h	Sun Sep 29 14:40:43 2024 +0200
+++ b/src/cx/tree.h	Sun Sep 29 22:45:43 2024 +0200
@@ -664,6 +664,32 @@
 typedef struct cx_tree_class_s cx_tree_class;
 
 /**
+ * Base structure that can be used for tree nodes in a #CxTree.
+ */
+struct cx_tree_node_base_s {
+    /**
+     * Pointer to the parent.
+     */
+    struct cx_tree_node_base_s *parent;
+    /**
+     * Pointer to the first child.
+     */
+    struct cx_tree_node_base_s *children;
+    /**
+     * Pointer to the last child.
+     */
+    struct cx_tree_node_base_s *last_child;
+    /**
+     * Pointer to the previous sibling.
+     */
+    struct cx_tree_node_base_s *prev;
+    /**
+     * Pointer to the next sibling.
+     */
+    struct cx_tree_node_base_s *next;
+};
+
+/**
  * Structure for holding the base data of a tree.
  */
 struct cx_tree_s {
@@ -673,18 +699,28 @@
     const cx_tree_class *cl;
 
     /**
+     * Allocator to allocate new nodes.
+     */
+    CxAllocator *allocator;
+
+    /**
+     * A pointer to the root node.
+     *
+     * Will be \c NULL when \c size is 0.
+     */
+    struct cx_tree_node_base_s *root;
+
+    /**
      * A function to create new nodes.
      *
+     * Invocations to this function will receive a pointer to this tree
+     * structure as second argument.
+     *
      * Nodes MAY use #cx_tree_node_base_s as base layout, but do not need to.
      */
     cx_tree_node_create_func node_create;
 
     /**
-     * The pointer to additional data that is passed to the create function.
-     */
-    void *create_data;
-
-    /**
      * An optional simple destructor for the tree nodes.
      */
     cx_destructor_func simple_destructor;
@@ -742,32 +778,6 @@
 };
 
 /**
- * Base structure that can be used for tree nodes in a #CxTree.
- */
-struct cx_tree_node_base_s {
-    /**
-     * Pointer to the parent.
-     */
-    struct cx_tree_node_base_s *parent;
-    /**
-     * Pointer to the first child.
-     */
-    struct cx_tree_node_base_s *children;
-    /**
-     * Pointer to the last child.
-     */
-    struct cx_tree_node_base_s *last_child;
-    /**
-     * Pointer to the previous sibling.
-     */
-    struct cx_tree_node_base_s *prev;
-    /**
-     * Pointer to the next sibling.
-     */
-    struct cx_tree_node_base_s *next;
-};
-
-/**
  * Macro to roll out the #cx_tree_node_base_s structure with a custom
  * node type.
  */

mercurial