238#define cxTreeIteratorContinue(iterator) (iterator).skip = true; continue
246#define cxTreeVisitorContinue(visitor) cxTreeIteratorContinue(visitor)
270 ptrdiff_t loc_parent,
271 ptrdiff_t loc_children,
272 ptrdiff_t loc_last_child,
295 ptrdiff_t loc_parent,
296 ptrdiff_t loc_children,
297 ptrdiff_t loc_last_child,
305#define CX_TREE_SEARCH_INFINITE_DEPTH 0
399 ptrdiff_t loc_children,
436 ptrdiff_t loc_children,
465 ptrdiff_t loc_children,
491 ptrdiff_t loc_children,
566 ptrdiff_t loc_parent,
567 ptrdiff_t loc_children,
568 ptrdiff_t loc_last_child,
622 ptrdiff_t loc_parent,
623 ptrdiff_t loc_children,
624 ptrdiff_t loc_last_child,
684 ptrdiff_t loc_parent,
685 ptrdiff_t loc_children,
686 ptrdiff_t loc_last_child,
819#define CX_TREE_NODE_BASE(type) \
834#define cx_tree_node_base_layout \
835 offsetof(struct cx_tree_node_base_s, parent),\
836 offsetof(struct cx_tree_node_base_s, children),\
837 offsetof(struct cx_tree_node_base_s, last_child),\
838 offsetof(struct cx_tree_node_base_s, prev), \
839 offsetof(struct cx_tree_node_base_s, next)
928#define cxTreeClear(tree) cxTreeDestroySubtree(tree, tree->root)
1007#define cxTreeCreateSimple(\
1008 allocator, create_func, search_func, search_data_func \
1009) cxTreeCreate(allocator, create_func, search_func, search_data_func, \
1010cx_tree_node_base_layout)
1110 if (n == 0)
return 0;
1111 if (n == 1)
return 0 ==
cxTreeInsert(tree, data) ? 1 : 0;
1133 return tree->
cl->
find(tree, tree->
root, data, 0);
1163 return tree->
cl->
find(tree, subtree_root, data, max_depth);
1221 node, visit_on_exit,
1357 const void *old_parent,
1358 const void *new_parent
void(* cx_destructor_func2)(void *data, void *memory)
Function pointer type for destructor functions.
Definition allocator.h:129
void(* cx_destructor_func)(void *memory)
Function pointer type for destructor functions.
Definition allocator.h:116
Common definitions for various collection implementations.
Common definitions and feature checks.
#define cx_attr_export
Only used for building Windows DLLs.
Definition common.h:285
#define cx_attr_nonnull
All pointer arguments must be non-NULL.
Definition common.h:136
#define cx_attr_nodiscard
Warn about discarded return value.
Definition common.h:265
#define cx_attr_malloc
The attributed function always returns freshly allocated memory.
Definition common.h:151
#define cx_attr_access_w(...)
Specifies that the function will only write through the given pointer.
Definition common.h:241
#define cx_attr_nonnull_arg(...)
The specified pointer arguments must be non-NULL.
Definition common.h:141
#define cx_attr_dealloc(...)
Not supported in clang.
Definition common.h:167
#define CX_ITERATOR_BASE
Declares base attributes for an iterator.
Definition iterator.h:92
CxIterator cxIterator(const void *array, size_t elem_size, size_t elem_count)
Creates an iterator for the specified plain array.
#define cxIteratorRef(iter)
Obtains a reference to an arbitrary iterator.
Definition iterator.h:197
Structure holding the data for an allocator.
Definition allocator.h:84
Common data for all iterators.
Definition iterator.h:48
Internal iterator struct - use CxIterator.
Definition iterator.h:97
The class definition for arbitrary trees.
Definition tree.h:844
void *(* find)(struct cx_tree_s *tree, const void *subtree, const void *data, size_t depth)
Member function for finding a node.
Definition tree.h:871
size_t(* insert_many)(struct cx_tree_s *tree, struct cx_iterator_base_s *iter, size_t n)
Member function for inserting multiple elements.
Definition tree.h:862
int(* insert_element)(struct cx_tree_s *tree, const void *data)
Member function for inserting a single element.
Definition tree.h:851
A depth-first tree iterator.
Definition tree.h:63
bool skip
Indicates whether the subtree below the current node shall be skipped.
Definition tree.h:71
void ** stack
Internal stack.
Definition tree.h:111
bool visit_on_exit
Set to true, when the iterator shall visit a node again when all it's children have been processed.
Definition tree.h:76
ptrdiff_t loc_next
Offset in the node struct for the next pointer.
Definition tree.h:88
size_t depth
The current depth in the tree.
Definition tree.h:124
void * node_next
Stores a copy of the next pointer of the visited node.
Definition tree.h:103
void * node
The currently observed node.
Definition tree.h:98
size_t stack_size
Internal stack size.
Definition tree.h:120
size_t counter
The total number of distinct nodes that have been passed so far.
Definition tree.h:92
ptrdiff_t loc_children
Offset in the node struct for the children linked list.
Definition tree.h:84
bool exiting
True, if this iterator is currently leaving the node.
Definition tree.h:80
size_t stack_capacity
Internal capacity of the stack.
Definition tree.h:115
Base structure that can be used for tree nodes in a CxTree.
Definition tree.h:700
struct cx_tree_node_base_s * children
Pointer to the first child.
Definition tree.h:708
struct cx_tree_node_base_s * prev
Pointer to the previous sibling.
Definition tree.h:716
struct cx_tree_node_base_s * last_child
Pointer to the last child.
Definition tree.h:712
struct cx_tree_node_base_s * parent
Pointer to the parent.
Definition tree.h:704
struct cx_tree_node_base_s * next
Pointer to the next sibling.
Definition tree.h:720
Structure for holding the base data of a tree.
Definition tree.h:726
ptrdiff_t loc_parent
Offset in the node struct for the parent pointer.
Definition tree.h:787
ptrdiff_t loc_children
Offset in the node struct for the children linked list.
Definition tree.h:792
ptrdiff_t loc_next
Offset in the node struct for the next sibling pointer.
Definition tree.h:808
cx_tree_search_data_func search_data
A function to compare a node with data.
Definition tree.h:777
cx_destructor_func2 advanced_destructor
An optional advanced destructor for the tree nodes.
Definition tree.h:762
cx_tree_node_create_func node_create
A function to create new nodes.
Definition tree.h:752
size_t size
The number of currently stored elements.
Definition tree.h:782
const CxAllocator * allocator
Allocator to allocate new nodes.
Definition tree.h:735
cx_tree_search_func search
A function to compare two nodes.
Definition tree.h:772
ptrdiff_t loc_last_child
Optional offset in the node struct for the pointer to the last child in the linked list (negative if ...
Definition tree.h:798
ptrdiff_t loc_prev
Offset in the node struct for the previous sibling pointer.
Definition tree.h:803
void * destructor_data
The pointer to additional data that is passed to the advanced destructor.
Definition tree.h:767
const cx_tree_class * cl
The tree class definition.
Definition tree.h:730
void * root
A pointer to the root node.
Definition tree.h:742
cx_destructor_func simple_destructor
An optional simple destructor for the tree nodes.
Definition tree.h:757
An element in a visitor queue.
Definition tree.h:131
size_t depth
The depth of the node.
Definition tree.h:139
void * node
The tree node to visit.
Definition tree.h:135
struct cx_tree_visitor_queue_s * next
The next element in the queue or NULL.
Definition tree.h:143
A breadth-first tree iterator.
Definition tree.h:167
ptrdiff_t loc_next
Offset in the node struct for the next pointer.
Definition tree.h:183
struct cx_tree_visitor_queue_s * queue_last
The last element in the visitor queue.
Definition tree.h:205
size_t counter
The total number of distinct nodes that have been passed so far.
Definition tree.h:187
size_t depth
The current depth in the tree.
Definition tree.h:197
bool skip
Indicates whether the subtree below the current node shall be skipped.
Definition tree.h:175
void * node
The currently observed node.
Definition tree.h:193
ptrdiff_t loc_children
Offset in the node struct for the children linked list.
Definition tree.h:179
struct cx_tree_visitor_queue_s * queue_next
The next element in the visitor queue.
Definition tree.h:201
void cxTreeSetParent(CxTree *tree, void *parent, void *child)
Sets the (new) parent of the specified child.
void cx_tree_link(void *parent, void *node, ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Links a node to a (new) parent.
CxTreeIterator cx_tree_iterator(void *root, bool visit_on_exit, ptrdiff_t loc_children, ptrdiff_t loc_next)
Creates a depth-first iterator for a tree with the specified root node.
void cxTreeAddChildNode(CxTree *tree, void *parent, void *child)
Adds a new node to the tree.
static size_t cxTreeInsertArray(CxTree *tree, const void *data, size_t elem_size, size_t n)
Inserts an array of data efficiently into the tree.
Definition tree.h:1104
int(* cx_tree_search_func)(const void *node, const void *new_node)
Function pointer for a search function.
Definition tree.h:364
unsigned int cx_tree_add_look_around_depth
The local search depth for a new subtree when adding multiple elements.
int cxTreeDestroyNode(CxTree *tree, void *node, cx_tree_relink_func relink_func)
Destroys a node and re-links its children to its former parent.
static CxTreeIterator cxTreeIterate(CxTree *tree, bool visit_on_exit)
Creates a depth-first iterator for the specified tree.
Definition tree.h:1255
size_t cx_tree_add_array(const void *src, size_t num, size_t elem_size, cx_tree_search_func sfunc, cx_tree_node_create_func cfunc, void *cdata, void **failed, void *root, ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Adds multiple elements efficiently to a tree.
int cx_tree_search(const void *root, size_t depth, const void *node, cx_tree_search_func sfunc, void **result, ptrdiff_t loc_children, ptrdiff_t loc_next)
Searches for a node in a tree.
size_t cxTreeSubtreeDepth(CxTree *tree, void *subtree_root)
Determines the depth of the specified subtree.
void cxTreeDestroySubtree(CxTree *tree, void *node)
Destroys a node and it's subtree.
void(* cx_tree_relink_func)(void *node, const void *old_parent, const void *new_parent)
A function that is invoked when a node needs to be re-linked to a new parent.
Definition tree.h:1355
int(* cx_tree_search_data_func)(const void *node, const void *data)
Function pointer for a search function.
Definition tree.h:334
size_t cxTreeDepth(CxTree *tree)
Determines the depth of the entire tree.
static void * cxTreeFindInSubtree(CxTree *tree, const void *data, void *subtree_root, size_t max_depth)
Searches the data in the specified subtree.
Definition tree.h:1157
int cxTreeRemoveNode(CxTree *tree, void *node, cx_tree_relink_func relink_func)
Removes a node and re-links its children to its former parent.
static void * cxTreeFind(CxTree *tree, const void *data)
Searches the data in the specified tree.
Definition tree.h:1129
static CxTreeVisitor cxTreeVisit(CxTree *tree)
Creates a breadth-first iterator for the specified tree.
Definition tree.h:1271
struct cx_tree_visitor_s CxTreeVisitor
A breadth-first tree iterator.
static CxTreeVisitor cxTreeVisitSubtree(CxTree *tree, void *node)
Creates a breadth-first iterator for the specified tree starting in node.
Definition tree.h:1238
static CxTreeIterator cxTreeIterateSubtree(CxTree *tree, void *node, bool visit_on_exit)
Creates a depth-first iterator for the specified tree starting in node.
Definition tree.h:1215
CxTree * cxTreeCreateWrapped(const CxAllocator *allocator, void *root, ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Creates a new tree structure based on an existing tree.
void cxTreeFree(CxTree *tree)
Deallocates the tree structure.
size_t cxTreeSubtreeSize(CxTree *tree, void *subtree_root)
Determines the size of the specified subtree.
static void cxTreeVisitorDispose(CxTreeVisitor *visitor)
Releases internal memory of the given tree visitor.
Definition tree.h:223
int cxTreeAddChild(CxTree *tree, void *parent, const void *data)
Creates a new node and adds it to the tree.
void cx_tree_unlink(void *node, ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Unlinks a node from its parent.
void *(* cx_tree_node_create_func)(const void *, void *)
Describes a function that creates a tree node from the specified data.
Definition tree.h:506
static size_t cxTreeInsertIter(CxTree *tree, CxIteratorBase *iter, size_t n)
Inserts elements provided by an iterator efficiently into the tree.
Definition tree.h:1082
size_t cx_tree_add_iter(struct cx_iterator_base_s *iter, size_t num, cx_tree_search_func sfunc, cx_tree_node_create_func cfunc, void *cdata, void **failed, void *root, ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Adds multiple elements efficiently to a tree.
struct cx_tree_iterator_s CxTreeIterator
A depth-first tree iterator.
int cx_tree_search_data(const void *root, size_t depth, const void *data, cx_tree_search_data_func sfunc, void **result, ptrdiff_t loc_children, ptrdiff_t loc_next)
Searches for data in a tree.
CxTreeVisitor cx_tree_visitor(void *root, ptrdiff_t loc_children, ptrdiff_t loc_next)
Creates a breadth-first iterator for a tree with the specified root node.
int cx_tree_add(const void *src, cx_tree_search_func sfunc, cx_tree_node_create_func cfunc, void *cdata, void **cnode, void *root, ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Adds data to a tree.
static void cxTreeIteratorDispose(CxTreeIterator *iter)
Releases internal memory of the given tree iterator.
Definition tree.h:213
static int cxTreeInsert(CxTree *tree, const void *data)
Inserts data into the tree.
Definition tree.h:1062
void cxTreeRemoveSubtree(CxTree *tree, void *node)
Removes a node and it's subtree from the tree.
CxTree * cxTreeCreate(const CxAllocator *allocator, cx_tree_node_create_func create_func, cx_tree_search_func search_func, cx_tree_search_data_func search_data_func, ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child, ptrdiff_t loc_prev, ptrdiff_t loc_next)
Creates a new tree structure based on the specified layout.