1. 定义一棵avl树
struct avl_tree services;
2. 初始化avl树
int avl_strcmp(const void *k1, const void *k2, void *ptr)
{
return strcmp(k1, k2);
}
avl_init(&services, avl_strcmp, false, NULL);
3. 插入结点
struct service {
struct avl_node avl;
...
};
struct service *s = service_alloc(name);
avl_insert(&services, &s->avl);
4. 删除结点
avl_delete(&services, &s->avl);
5. 遍历结点
avl_for_each_element(&services, s, avl)
service_dump(s);
6. 查找结点
s = avl_find_element(&services, name, s, avl);