核心对红黑树使用两点说明
1、头文件
<Documentation/rbtree.txt>
Linux's rbtree implementation lives in the file "lib/rbtree.c". To use it,
"#include <linux/rbtree.h>".
2、自我封装
<linux/rbtree.h>
To use rbtrees you'll have to implementyour own insert and search cores. This will avoid us to use callbacks and todrop drammatically performances. I know it's not the cleaner way, but in C (not in C++) to get performances andgenericity...
【这里中心思想: 在使用rbtree时候,你需要自己实现你的插入和查询的核心代码,即使用核心API,自我封装。这可以避免使用回调函数和性能上的损失。(由于键值不同,调用用户定义的函数,就需要采用回调的形式;显然这里没有使用)】
The Linux rbtree implementation is optimized for speed, and thus has one less layer of indirection (and better cache locality) than more traditional tree implementations. Instead of using pointers to separate rb_node and data structures, each instance of struct rb_node is embedded in the data structure it organizes. And instead of using a comparison callback function pointer, users are expected to write their own tree search and insert functions which call the provided rbtree functions. Locking is also left up to the user of the rbtree code.
【在Linux rbtree实现了速度优化,具有比传统树的实现要少一个间接层(和更好的缓存)。每个struct rb_node实例是嵌入在数据组织成的结构体中,以此代替使用指针来区分rb_node和数据结构。并且相比采用回调函数的指针形式,用户可以通过调用rbtree提供的函数,写自己的树搜索和插入函数。锁也留给使用rbtree代码的用户自己管理。