summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/include/linux/rbtree_augmented.h36
1 files changed, 35 insertions, 1 deletions
diff --git a/tools/include/linux/rbtree_augmented.h b/tools/include/linux/rbtree_augmented.h
index de3a480204ba..4e8c4c76e9a2 100644
--- a/tools/include/linux/rbtree_augmented.h
+++ b/tools/include/linux/rbtree_augmented.h
@@ -63,7 +63,7 @@ rb_insert_augmented_cached(struct rb_node *node,
63} 63}
64 64
65/* 65/*
66 * Template for declaring augmented rbtree callbacks 66 * Template for declaring augmented rbtree callbacks (generic case)
67 * 67 *
68 * RBSTATIC: 'static' or empty 68 * RBSTATIC: 'static' or empty
69 * RBNAME: name of the rb_augment_callbacks structure 69 * RBNAME: name of the rb_augment_callbacks structure
@@ -109,6 +109,40 @@ RBSTATIC const struct rb_augment_callbacks RBNAME = { \
109 .rotate = RBNAME ## _rotate \ 109 .rotate = RBNAME ## _rotate \
110}; 110};
111 111
112/*
113 * Template for declaring augmented rbtree callbacks,
114 * computing RBAUGMENTED scalar as max(RBCOMPUTE(node)) for all subtree nodes.
115 *
116 * RBSTATIC: 'static' or empty
117 * RBNAME: name of the rb_augment_callbacks structure
118 * RBSTRUCT: struct type of the tree nodes
119 * RBFIELD: name of struct rb_node field within RBSTRUCT
120 * RBTYPE: type of the RBAUGMENTED field
121 * RBAUGMENTED: name of RBTYPE field within RBSTRUCT holding data for subtree
122 * RBCOMPUTE: name of function that returns the per-node RBTYPE scalar
123 */
124
125#define RB_DECLARE_CALLBACKS_MAX(RBSTATIC, RBNAME, RBSTRUCT, RBFIELD, \
126 RBTYPE, RBAUGMENTED, RBCOMPUTE) \
127static inline RBTYPE RBNAME ## _compute_max(RBSTRUCT *node) \
128{ \
129 RBSTRUCT *child; \
130 RBTYPE max = RBCOMPUTE(node); \
131 if (node->RBFIELD.rb_left) { \
132 child = rb_entry(node->RBFIELD.rb_left, RBSTRUCT, RBFIELD); \
133 if (child->RBAUGMENTED > max) \
134 max = child->RBAUGMENTED; \
135 } \
136 if (node->RBFIELD.rb_right) { \
137 child = rb_entry(node->RBFIELD.rb_right, RBSTRUCT, RBFIELD); \
138 if (child->RBAUGMENTED > max) \
139 max = child->RBAUGMENTED; \
140 } \
141 return max; \
142} \
143RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME, RBSTRUCT, RBFIELD, \
144 RBTYPE, RBAUGMENTED, RBNAME ## _compute_max)
145
112 146
113#define RB_RED 0 147#define RB_RED 0
114#define RB_BLACK 1 148#define RB_BLACK 1