1.在你的所要使用的模块中包含头文件
#include<linux/rb_tree.h>
2.将rb_node嵌入到自己结构体中
struct my_data{
struct rb_node node;
char key[32];
char value[32]
};
3.定义rb树的根,一般为全局变量
struct rb_root my_root_tree = RB_ROOT;
4.实现自己的查找,遍历,插入等函数
比较函数定义:
int compare_id(char* key1, char *key2)
{
return strcmp(key1,key2);
}
查找函数:
struct my_data* my_search(struct rb_root *root