src/cx/tree.h

changeset 904
cdc49211d87f
parent 903
a018f5916d3b
child 905
39aa4f106a71
--- a/src/cx/tree.h	Thu Oct 03 15:42:35 2024 +0200
+++ b/src/cx/tree.h	Thu Oct 03 16:31:09 2024 +0200
@@ -905,11 +905,12 @@
  *
  * Nodes created by \p create_func MUST contain #cx_tree_node_base_s as first
  * member (or at least respect the default offsets specified in the tree
- * struct) and they MUST be allocated with the default stdlib allocator.
+ * struct) and they MUST be allocated with the specified allocator.
  *
  * \note This function will also register an advanced destructor which
- * will free the nodes with the #cxDefaultAllocator.
+ * will free the nodes with the allocator's free() method.
  *
+ * @param allocator the allocator that shall be used
  * @param create_func a function that creates new nodes
  * @param search_func a function that compares two nodes
  * @return the new tree
@@ -917,11 +918,16 @@
  */
 __attribute__((__nonnull__, __warn_unused_result__))
 static inline CxTree *cxTreeCreateSimple(
+        const CxAllocator *allocator,
         cx_tree_node_create_func create_func,
         cx_tree_search_func search_func
 ) {
-    return cxTreeCreate(cxDefaultAllocator,
-            create_func, search_func, cx_tree_node_base_layout);
+    return cxTreeCreate(
+            allocator,
+            create_func,
+            search_func,
+            cx_tree_node_base_layout
+    );
 }
 
 /**
@@ -960,9 +966,8 @@
  *
  * \attention This function will only invoke the destructor functions
  * on the nodes, if specified.
- * It will NOT automatically free the nodes with the allocator, because that
- * will cause a double-free in scenarios where this tree structure is wrapping
- * a tree which memory is managed by someone else.
+ * It will NOT additionally free the nodes with the tree's allocator, because
+ * that would cause a double-free in most scenarios.
  *
  * @param tree the tree to destroy
  */
@@ -1034,7 +1039,7 @@
     if (n == 0) return 0;
     if (n == 1) return 0 == cxTreeInsert(tree, data) ? 1 : 0;
     CxIterator iter = cxIterator(data, elem_size, n);
-    return tree->cl->insert_many(tree, cxIteratorRef(iter), n);
+    return cxTreeInsertIter(tree, cxIteratorRef(iter), n);
 }
 
 /**

mercurial