MOS Source Code
Loading...
Searching...
No Matches
tree.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
5#include <mos/moslib_global.h>
6#include <mos_string.h>
7
9{
10 linked_list_init(&node->list_node);
12}
13
15{
16 MOS_LIB_ASSERT(parent != NULL);
17 MOS_LIB_ASSERT(child != NULL);
18 MOS_LIB_ASSERT(child->parent == NULL);
19
20 child->parent = parent;
21 MOS_LIB_ASSERT_X(list_is_empty(&child->children), "Child node already has children");
22
24 list_node_append(&parent->children, &child->list_node);
25}
MOSAPI void linked_list_init(list_node_t *head_node)
Initialise a circular double linked list.
Definition list.c:15
MOSAPI void list_node_append(list_node_t *head, list_node_t *item)
Definition list.c:68
MOSAPI bool list_is_empty(const list_node_t *head)
Definition list.c:21
#define NULL
Definition pb_syshdr.h:46
#define MOS_LIB_ASSERT_X(cond, msg)
Definition rpc_server.c:25
#define MOS_LIB_ASSERT(cond)
Definition rpc_server.c:26
list_head children
Definition tree.h:15
tree_node_t * parent
Definition tree.h:14
void tree_node_init(tree_node_t *node)
Definition tree.c:8
void tree_add_child(tree_node_t *parent, tree_node_t *child)
Definition tree.c:14