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 13 #include <rtthread.h> 14 15 #include <string.h> 16 #include <stdint.h> 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 #define avl_key_t size_t 23 #define AVL_EMPTY (struct lwp_avl_struct *)0 24 #define avl_maxheight 32 25 #define heightof(tree) ((tree) == AVL_EMPTY ? 0 : (tree)->avl_height) 26 27 struct lwp_avl_struct 28 { 29 struct lwp_avl_struct *avl_left; 30 struct lwp_avl_struct *avl_right; 31 int avl_height; 32 avl_key_t avl_key; 33 void *data; 34 }; 35 36 void lwp_avl_remove(struct lwp_avl_struct * node_to_delete, struct lwp_avl_struct ** ptree); 37 void lwp_avl_insert (struct lwp_avl_struct * new_node, struct lwp_avl_struct ** ptree); 38 struct lwp_avl_struct* lwp_avl_find(avl_key_t key, struct lwp_avl_struct* ptree); 39 int lwp_avl_traversal(struct lwp_avl_struct* ptree, int (*fun)(struct lwp_avl_struct*, void *), void *arg); 40 struct lwp_avl_struct* lwp_map_find_first(struct lwp_avl_struct* ptree); 41 42 #ifdef __cplusplus 43 } 44 #endif 45 46 #endif /* LWP_AVL_H__ */ 47