src/ucx/cx/tree.h

changeset 582
82b60a8dd55c
parent 579
e10457d74fe1
child 621
956c03c25edd
--- a/src/ucx/cx/tree.h	Mon May 26 21:02:30 2025 +0200
+++ b/src/ucx/cx/tree.h	Mon May 26 21:06:17 2025 +0200
@@ -120,6 +120,7 @@
         size_t stack_size;
         /**
          * The current depth in the tree.
+         * The node with which the iteration starts has depth 1.
          */
         size_t depth;
     };
@@ -135,6 +136,7 @@
     void *node;
     /**
      * The depth of the node.
+     * The first visited node has depth 1.
      */
     size_t depth;
     /**
@@ -211,7 +213,7 @@
  */
 cx_attr_nonnull
 static inline void cxTreeIteratorDispose(CxTreeIterator *iter) {
-    free(iter->stack);
+    cxFreeDefault(iter->stack);
     iter->stack = NULL;
 }
 
@@ -224,7 +226,7 @@
     struct cx_tree_visitor_queue_s *q = visitor->queue_next;
     while (q != NULL) {
         struct cx_tree_visitor_queue_s *next = q->next;
-        free(q);
+        cxFreeDefault(q);
         q = next;
     }
 }
@@ -441,7 +443,7 @@
  * Creates a depth-first iterator for a tree with the specified root node.
  *
  * @note A tree iterator needs to maintain a stack of visited nodes, which is
- * allocated using stdlib malloc().
+ * allocated using the cxDefaultAllocator.
  * When the iterator becomes invalid, this memory is automatically released.
  * However, if you wish to cancel the iteration before the iterator becomes
  * invalid by itself, you MUST call cxTreeIteratorDispose() manually to release
@@ -469,8 +471,8 @@
 /**
  * Creates a breadth-first iterator for a tree with the specified root node.
  *
- * @note A tree visitor needs to maintain a queue of to be visited nodes, which
- * is allocated using stdlib malloc().
+ * @note A tree visitor needs to maintain a queue of to-be visited nodes, which
+ * is allocated using the cxDefaultAllocator.
  * When the visitor becomes invalid, this memory is automatically released.
  * However, if you wish to cancel the iteration before the visitor becomes
  * invalid by itself, you MUST call cxTreeVisitorDispose() manually to release
@@ -956,7 +958,7 @@
  * will free the nodes with the allocator's free() method.
  *
  * @param allocator the allocator that shall be used
- * (if @c NULL, a default stdlib allocator will be used)
+ * (if @c NULL, the cxDefaultAllocator will be used)
  * @param create_func a function that creates new nodes
  * @param search_func a function that compares two nodes
  * @param search_data_func a function that compares a node with data
@@ -1020,7 +1022,7 @@
  * tree, you need to specify those functions afterwards.
  *
  * @param allocator the allocator that was used for nodes of the wrapped tree
- * (if @c NULL, a default stdlib allocator is assumed)
+ * (if @c NULL, the cxDefaultAllocator is assumed)
  * @param root the root node of the tree that shall be wrapped
  * @param loc_parent offset in the node struct for the parent pointer
  * @param loc_children offset in the node struct for the children linked list
@@ -1188,6 +1190,18 @@
 size_t cxTreeSubtreeDepth(CxTree *tree, void *subtree_root);
 
 /**
+ * Determines the size of the entire tree.
+ *
+ * @param tree the tree
+ * @return the tree size, counting the root as one
+ */
+cx_attr_nonnull
+cx_attr_nodiscard
+static inline size_t cxTreeSize(CxTree *tree) {
+    return tree->size;
+}
+
+/**
  * Determines the depth of the entire tree.
  *
  * @param tree the tree

mercurial