执行以下操作是否有效
struct foo {
int data;
struct rb_node node
};
struct rb_root root;
/* Filling tree with kalloc'ed foo nodes */
struct rb_node *node=rb_first(&root);
while (node)
{
struct rb_node *next=rb_next(node);
kfree(node);
node = next;
}
root=RB_ROOT;
事实上,我只想以线性时间同时执行 foreach 和clear。
最佳答案
探索了 rb_next 实现。它先返回父项,然后再返回右子项。 所以,用这种方式清除列表是不可能的。
关于Linux 内核 rb 树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10958906/