simplify tree class

Sun, 06 Oct 2024 13:41:26 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 06 Oct 2024 13:41:26 +0200
changeset 914
7da30512efc4
parent 913
72db8e42b95e
child 915
23db9f0c1acd

simplify tree class

src/cx/tree.h file | annotate | diff | comparison | revisions
src/tree.c file | annotate | diff | comparison | revisions
--- a/src/cx/tree.h	Sun Oct 06 13:37:05 2024 +0200
+++ b/src/cx/tree.h	Sun Oct 06 13:41:26 2024 +0200
@@ -841,19 +841,6 @@
             const void *subtree,
             const void *data
     );
-
-    /**
-     * Member function for creating an iterator for the tree.
-     */
-    CxTreeIterator (*iterator)(
-            struct cx_tree_s *tree,
-            bool visit_on_exit
-    );
-
-    /**
-     * Member function for creating a visitor for the tree.
-     */
-    CxTreeVisitor (*visitor)(struct cx_tree_s *tree);
 };
 
 /**
@@ -1113,7 +1100,10 @@
         CxTree *tree,
         bool visit_on_exit
 ) {
-    return tree->cl->iterator(tree, visit_on_exit);
+    return cx_tree_iterator(
+            tree->root, visit_on_exit,
+            tree->loc_children, tree->loc_next
+    );
 }
 
 /**
@@ -1125,7 +1115,9 @@
  */
 __attribute__((__nonnull__, __warn_unused_result__))
 static inline CxTreeVisitor cxTreeVisitor(CxTree *tree) {
-    return tree->cl->visitor(tree);
+    return cx_tree_visitor(
+            tree->root, tree->loc_children, tree->loc_next
+    );
 }
 
 /**
--- a/src/tree.c	Sun Oct 06 13:37:05 2024 +0200
+++ b/src/tree.c	Sun Oct 06 13:41:26 2024 +0200
@@ -681,20 +681,6 @@
                             loc_prev, loc_next);
 }
 
-static CxTreeIterator cx_tree_default_iterator(
-        CxTree *tree,
-        bool visit_on_exit
-) {
-    return cx_tree_iterator(
-            tree->root, visit_on_exit,
-            tree->loc_children, tree->loc_next
-    );
-}
-
-static CxTreeVisitor cx_tree_default_visitor(CxTree *tree) {
-    return cx_tree_visitor(tree->root, tree->loc_children, tree->loc_next);
-}
-
 static int cx_tree_default_insert_element(
         CxTree *tree,
         const void *data
@@ -770,9 +756,7 @@
 static cx_tree_class cx_tree_default_class = {
         cx_tree_default_insert_element,
         cx_tree_default_insert_many,
-        cx_tree_default_find,
-        cx_tree_default_iterator,
-        cx_tree_default_visitor
+        cx_tree_default_find
 };
 
 CxTree *cxTreeCreate(
@@ -876,7 +860,9 @@
 }
 
 size_t cxTreeDepth(CxTree *tree) {
-    CxTreeVisitor visitor = tree->cl->visitor(tree);
+    CxTreeVisitor visitor = cx_tree_visitor(
+            tree->root, tree->loc_children, tree->loc_next
+    );
     while (cxIteratorValid(visitor)) {
         cxIteratorNext(visitor);
     }

mercurial