lwp_avl.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2006-2025 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-10-12 Jesven first version
  9. */
  10. #ifndef LWP_AVL_H__
  11. #define LWP_AVL_H__
  12. #include <rtthread.h>
  13. #include <string.h>
  14. #include <stdint.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #define avl_key_t size_t
  19. #define AVL_EMPTY (struct lwp_avl_struct *)0
  20. #define avl_maxheight 32
  21. #define heightof(tree) ((tree) == AVL_EMPTY ? 0 : (tree)->avl_height)
  22. /**
  23. * @brief AVL tree node structure for thread ID (tid) or Process ID (pid) management
  24. */
  25. struct lwp_avl_struct
  26. {
  27. struct lwp_avl_struct *avl_left; /**< Pointer to left child node */
  28. struct lwp_avl_struct *avl_right; /**< Pointer to right child node */
  29. int avl_height; /**< Height of the node in the AVL tree */
  30. avl_key_t avl_key; /**< Key value used for AVL tree node comparison */
  31. void *data; /**< Pointer to associated data */
  32. };
  33. void lwp_avl_remove(struct lwp_avl_struct * node_to_delete, struct lwp_avl_struct ** ptree);
  34. void lwp_avl_insert (struct lwp_avl_struct * new_node, struct lwp_avl_struct ** ptree);
  35. struct lwp_avl_struct* lwp_avl_find(avl_key_t key, struct lwp_avl_struct* ptree);
  36. int lwp_avl_traversal(struct lwp_avl_struct* ptree, int (*fun)(struct lwp_avl_struct*, void *), void *arg);
  37. struct lwp_avl_struct* lwp_map_find_first(struct lwp_avl_struct* ptree);
  38. #ifdef __cplusplus
  39. }
  40. #endif
  41. #endif /* LWP_AVL_H__ */