Lines Matching +full:in +full:- +full:tree

1 /* SPDX-License-Identifier: GPL-2.0-or-later */
11 I know it's not the cleaner way, but in C (not in C++) to get
14 See Documentation/core-api/rbtree.rst for documentation and samples.
26 #define rb_parent(r) ((struct rb_node *)((r)->__rb_parent_color & ~3))
30 #define RB_EMPTY_ROOT(root) (READ_ONCE((root)->rb_node) == NULL)
32 /* 'empty' nodes are nodes that are known not to be inserted in an rbtree */
34 ((node)->__rb_parent_color == (unsigned long)(node))
36 ((node)->__rb_parent_color = (unsigned long)(node))
43 /* Find logical next and previous nodes in a tree */
49 /* Postorder iteration - always visit the parent after its children */
62 node->__rb_parent_color = (unsigned long)parent; in rb_link_node()
63 node->rb_left = node->rb_right = NULL; in rb_link_node()
71 node->__rb_parent_color = (unsigned long)parent; in rb_link_node_rcu()
72 node->rb_left = node->rb_right = NULL; in rb_link_node_rcu()
83 * rbtree_postorder_for_each_entry_safe - iterate in post-order over rb_root of
95 * Note, however, that it cannot handle other modifications that re-order the
97 * rb_erase() may rebalance the tree, causing us to miss some nodes.
101 pos && ({ n = rb_entry_safe(rb_next_postorder(&pos->field), \
106 #define rb_first_cached(root) (root)->rb_leftmost
113 root->rb_leftmost = node; in rb_insert_color_cached()
114 rb_insert_color(node, &root->rb_root); in rb_insert_color_cached()
123 if (root->rb_leftmost == node) in rb_erase_cached()
124 leftmost = root->rb_leftmost = rb_next(node); in rb_erase_cached()
126 rb_erase(node, &root->rb_root); in rb_erase_cached()
135 if (root->rb_leftmost == victim) in rb_replace_node_cached()
136 root->rb_leftmost = new; in rb_replace_node_cached()
137 rb_replace_node(victim, new, &root->rb_root); in rb_replace_node_cached()
144 * comp(a->key,b) < 0 := less(a,b)
145 * comp(a->key,b) > 0 := less(b,a)
146 * comp(a->key,b) == 0 := !less(a,b) && !less(b,a)
153 * on-stack dummy object, which might not be feasible due to object size.
157 * rb_add_cached() - insert @node into the leftmost cached tree @tree
159 * @tree: leftmost cached tree to insert @node into
165 rb_add_cached(struct rb_node *node, struct rb_root_cached *tree, in rb_add_cached() argument
168 struct rb_node **link = &tree->rb_root.rb_node; in rb_add_cached()
175 link = &parent->rb_left; in rb_add_cached()
177 link = &parent->rb_right; in rb_add_cached()
183 rb_insert_color_cached(node, tree, leftmost); in rb_add_cached()
189 * rb_add() - insert @node into @tree
191 * @tree: tree to insert @node into
195 rb_add(struct rb_node *node, struct rb_root *tree, in rb_add() argument
198 struct rb_node **link = &tree->rb_node; in rb_add()
204 link = &parent->rb_left; in rb_add()
206 link = &parent->rb_right; in rb_add()
210 rb_insert_color(node, tree); in rb_add()
214 * rb_find_add() - find equivalent @node in @tree, or add @node
215 * @node: node to look-for / insert
216 * @tree: tree to search / modify
223 rb_find_add(struct rb_node *node, struct rb_root *tree, in rb_find_add() argument
226 struct rb_node **link = &tree->rb_node; in rb_find_add()
235 link = &parent->rb_left; in rb_find_add()
237 link = &parent->rb_right; in rb_find_add()
243 rb_insert_color(node, tree); in rb_find_add()
248 * rb_find_add_rcu() - find equivalent @node in @tree, or add @node
249 * @node: node to look-for / insert
250 * @tree: tree to search / modify
253 * Adds a Store-Release for link_node.
259 rb_find_add_rcu(struct rb_node *node, struct rb_root *tree, in rb_find_add_rcu() argument
262 struct rb_node **link = &tree->rb_node; in rb_find_add_rcu()
271 link = &parent->rb_left; in rb_find_add_rcu()
273 link = &parent->rb_right; in rb_find_add_rcu()
279 rb_insert_color(node, tree); in rb_find_add_rcu()
284 * rb_find() - find @key in tree @tree
286 * @tree: tree to search
292 rb_find(const void *key, const struct rb_root *tree, in rb_find() argument
295 struct rb_node *node = tree->rb_node; in rb_find()
301 node = node->rb_left; in rb_find()
303 node = node->rb_right; in rb_find()
312 * rb_find_rcu() - find @key in tree @tree
314 * @tree: tree to search
317 * Notably, tree descent vs concurrent tree rotations is unsound and can result
318 * in false-negatives.
323 rb_find_rcu(const void *key, const struct rb_root *tree, in rb_find_rcu() argument
326 struct rb_node *node = tree->rb_node; in rb_find_rcu()
332 node = rcu_dereference_raw(node->rb_left); in rb_find_rcu()
334 node = rcu_dereference_raw(node->rb_right); in rb_find_rcu()
343 * rb_find_first() - find the first @key in @tree
345 * @tree: tree to search
351 rb_find_first(const void *key, const struct rb_root *tree, in rb_find_first() argument
354 struct rb_node *node = tree->rb_node; in rb_find_first()
363 node = node->rb_left; in rb_find_first()
365 node = node->rb_right; in rb_find_first()
373 * rb_next_match() - find the next @key in @tree
375 * @tree: tree to search
391 * rb_for_each() - iterates a subtree matching @key
394 * @tree: tree to search
397 #define rb_for_each(node, key, tree, cmp) \ argument
398 for ((node) = rb_find_first((key), (tree), (cmp)); \