MCPcopy Index your code
hub / github.com/RT-Thread/rt-thread / lwp_avl_insert

Function lwp_avl_insert

components/lwp/lwp_avl.c:168–192  ·  view source on GitHub ↗

* @brief Inserts a new node into an AVL tree while maintaining balance * * @param[in] new_node The new node to be inserted into the AVL tree * @param[in,out] ptree Pointer to the root node pointer of the AVL tree * * @note Uses a stack to track the insertion path for rebalancing */

Source from the content-addressed store, hash-verified

166 * @note Uses a stack to track the insertion path for rebalancing
167 */
168void lwp_avl_insert(struct lwp_avl_struct *new_node, struct lwp_avl_struct **ptree)
169{
170 avl_key_t key = new_node->avl_key;
171 struct lwp_avl_struct **nodeplace = ptree;
172 struct lwp_avl_struct **stack[avl_maxheight];
173 int stack_count = 0;
174 struct lwp_avl_struct ***stack_ptr = &stack[0]; /* = &stack[stackcount] */
175 for (;;)
176 {
177 struct lwp_avl_struct *node = *nodeplace;
178 if (node == AVL_EMPTY)
179 break;
180 *stack_ptr++ = nodeplace;
181 stack_count++;
182 if (key < node->avl_key)
183 nodeplace = &node->avl_left;
184 else
185 nodeplace = &node->avl_right;
186 }
187 new_node->avl_left = AVL_EMPTY;
188 new_node->avl_right = AVL_EMPTY;
189 new_node->avl_height = 1;
190 *nodeplace = new_node;
191 lwp_avl_rebalance(stack_ptr, stack_count);
192}
193
194/**
195 * @brief Finds a node in an AVL tree by key

Callers 5

lwp_pid_get_lockedFunction · 0.85
lwp_user_object_addFunction · 0.85
_pftx_create_lockedFunction · 0.85
lwp_tid_getFunction · 0.85
_lwp_shmgetFunction · 0.85

Calls 1

lwp_avl_rebalanceFunction · 0.85

Tested by

no test coverage detected