Changeset 651 for GPL/branches/uniaud32-next/include/linux/rbtree.h
- Timestamp:
- Jan 23, 2021, 10:25:24 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/branches/uniaud32-next/include/linux/rbtree.h
r625 r651 1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 1 2 /* 2 3 Red Black Trees 3 4 (C) 1999 Andrea Arcangeli <andrea@suse.de> 4 5 5 This program is free software; you can redistribute it and/or modify6 it under the terms of the GNU General Public License as published by7 the Free Software Foundation; either version 2 of the License, or8 (at your option) any later version.9 10 This program is distributed in the hope that it will be useful,11 but WITHOUT ANY WARRANTY; without even the implied warranty of12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 GNU General Public License for more details.14 15 You should have received a copy of the GNU General Public License16 along with this program; if not, write to the Free Software17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18 6 19 7 linux/include/linux/rbtree.h … … 24 12 performances and genericity... 25 13 26 See Documentation/ rbtree.txt for documentation and samples.14 See Documentation/core-api/rbtree.rst for documentation and samples. 27 15 */ 28 /* from 4.19.163*/16 /* from 5.10.10 */ 29 17 30 18 #ifndef _LINUX_RBTREE_H … … 46 34 }; 47 35 48 /*49 * Leftmost-cached rbtrees.50 *51 * We do not cache the rightmost node based on footprint52 * size vs number of potential users that could benefit53 * from O(1) rb_last(). Just not worth it, users that want54 * this feature can always implement the logic explicitly.55 * Furthermore, users that want to cache both pointers may56 * find it a bit asymmetric, but that's ok.57 */58 struct rb_root_cached {59 struct rb_root rb_root;60 struct rb_node *rb_leftmost;61 };62 63 36 #define rb_parent(r) ((struct rb_node *)((r)->__rb_parent_color & ~3)) 64 37 65 38 #define RB_ROOT (struct rb_root) { NULL, } 66 #define RB_ROOT_CACHED (struct rb_root_cached) { {NULL, }, NULL }67 39 #define rb_entry(ptr, type, member) container_of(ptr, type, member) 68 40 … … 86 58 extern struct rb_node *rb_last(const struct rb_root *); 87 59 88 extern void rb_insert_color_cached(struct rb_node *,89 struct rb_root_cached *, bool);90 extern void rb_erase_cached(struct rb_node *node, struct rb_root_cached *);91 /* Same as rb_first(), but O(1) */92 #define rb_first_cached(root) (root)->rb_leftmost93 94 60 /* Postorder iteration - always visit the parent after its children */ 95 61 extern struct rb_node *rb_first_postorder(const struct rb_root *); … … 101 67 extern void rb_replace_node_rcu(struct rb_node *victim, struct rb_node *new, 102 68 struct rb_root *root); 103 extern void rb_replace_node_cached(struct rb_node *victim, struct rb_node *new,104 struct rb_root_cached *root);105 69 106 70 static inline void rb_link_node(struct rb_node *node, struct rb_node *parent, … … 152 116 pos = n) 153 117 118 /* 119 * Leftmost-cached rbtrees. 120 * 121 * We do not cache the rightmost node based on footprint 122 * size vs number of potential users that could benefit 123 * from O(1) rb_last(). Just not worth it, users that want 124 * this feature can always implement the logic explicitly. 125 * Furthermore, users that want to cache both pointers may 126 * find it a bit asymmetric, but that's ok. 127 */ 128 struct rb_root_cached { 129 struct rb_root rb_root; 130 struct rb_node *rb_leftmost; 131 }; 132 133 #define RB_ROOT_CACHED (struct rb_root_cached) { {NULL, }, NULL } 134 135 /* Same as rb_first(), but O(1) */ 136 #define rb_first_cached(root) (root)->rb_leftmost 137 138 static inline void rb_insert_color_cached(struct rb_node *node, 139 struct rb_root_cached *root, 140 bool leftmost) 141 { 142 if (leftmost) 143 root->rb_leftmost = node; 144 rb_insert_color(node, &root->rb_root); 145 } 146 147 static inline void rb_erase_cached(struct rb_node *node, 148 struct rb_root_cached *root) 149 { 150 if (root->rb_leftmost == node) 151 root->rb_leftmost = rb_next(node); 152 rb_erase(node, &root->rb_root); 153 } 154 155 static inline void rb_replace_node_cached(struct rb_node *victim, 156 struct rb_node *new, 157 struct rb_root_cached *root) 158 { 159 if (root->rb_leftmost == victim) 160 root->rb_leftmost = new; 161 rb_replace_node(victim, new, &root->rb_root); 162 } 163 154 164 #endif /* _LINUX_RBTREE_H */
Note:
See TracChangeset
for help on using the changeset viewer.