lwp_avl.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2006-2020, 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. struct lwp_avl_struct
  23. {
  24. struct lwp_avl_struct *avl_left;
  25. struct lwp_avl_struct *avl_right;
  26. int avl_height;
  27. avl_key_t avl_key;
  28. void *data;
  29. };
  30. void lwp_avl_remove(struct lwp_avl_struct * node_to_delete, struct lwp_avl_struct ** ptree);
  31. void lwp_avl_insert (struct lwp_avl_struct * new_node, struct lwp_avl_struct ** ptree);
  32. struct lwp_avl_struct* lwp_avl_find(avl_key_t key, struct lwp_avl_struct* ptree);
  33. int lwp_avl_traversal(struct lwp_avl_struct* ptree, int (*fun)(struct lwp_avl_struct*, void *), void *arg);
  34. struct lwp_avl_struct* lwp_map_find_first(struct lwp_avl_struct* ptree);
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. #endif /* LWP_AVL_H__ */