|
|
#define | AVL_EMPTY_NODE ((avl_t){0}) |
| | Create an empty AVL node, with no child nor parent.
|
| |
AVL
An AVL tree is a self-balancing BST where the difference between heights of left and right subtrees for any node cannot be more than one.
see: https://en.wikipedia.org/wiki/AVL_tree
Design
This library is designed to be used with intrusive structs. As such, it does NOT allocate nor free any memory whatsoever.
This design is highly inspired by linux's intrusive linked lists: https://www.data-structures-in-practice.com/intrusive-linked-lists/
◆ avl_compare_t
| typedef int(* avl_compare_t) (const avl_t *left, const avl_t *right) |
It performs an arbitrary comparison between 2 AVL nodes.
- Returns
- 0 if both are equal equal, -1 if left is lower, 1 if its greater.
◆ avl_insert()
- Parameters
-
| root | The root of the AVL tree |
| new | The new node to insert inside the tree |
| compare | The comparison function used for this tree |
- Note
value is passed as the left parameter of comparison
- Returns
- The newly inserted node
◆ avl_max()
- Parameters
-
- Returns
- The maximum value's node, NULL if tree is empty
◆ avl_min()
- Parameters
-
- Returns
- The minimum value's node, NULL if tree is empty
◆ avl_print()
| void avl_print |
( |
avl_t * |
root, |
|
|
void(*)(const avl_t *) |
print |
|
) |
| |
The AVL is printed in an in-order depth-first way.
- Warning
- This function visits the tree recursively, this means a higher stack usage. Be careful when you use it, more particularily inside the kernel.
- Parameters
-
| root | The root of the AVL tree |
| print | The function used to print the content of a node |
◆ avl_remove()
- Parameters
-
| root | The root of the AVL tree |
| value | The value to remove from the AVL tree |
| compare | The comparison function used for this tree |
- Note
value is passed as the left parameter of comparison
- Returns
- The removed value if any, else NULL
◆ avl_search()
- Parameters
-
| root | The root of the AVL tree |
| value | The value to find |
| compare | The comparison function used for this AVL tree |
- Returns
- The found node if any, else NULL
Value must be of the AVL type to be used with the comparison function. But its content need not necessarily be complete, as long as it has the necesary content to perform the comparison operation.
- Note
value is passed as the left parameter of comparison