* [rfc -tip] lib,rb-tree - introduce rb_for_each helper
@ 2009-07-11 22:00 Cyrill Gorcunov
2009-07-11 22:29 ` Frederic Weisbecker
0 siblings, 1 reply; 5+ messages in thread
From: Cyrill Gorcunov @ 2009-07-11 22:00 UTC (permalink / raw)
To: Ingo Molnar, Frederic Weisbecker; +Cc: LKML, Peter Zijlstra
perftools already use a number of opencoded
for() iterators over rbtree. The patch introduce
rb_for_each helper for this purpose.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
---
The real conversion for this macro usage should be
done later.
Also I think having rb_for_each_entry for being used
with container_of inbetween could be convinient as
well.
Anyway if we don't need such a helper -- just drop
the patch.
include/linux/rbtree.h | 3 +++
1 file changed, 3 insertions(+)
Index: linux-2.6.git/include/linux/rbtree.h
=====================================================================
--- linux-2.6.git.orig/include/linux/rbtree.h
+++ linux-2.6.git/include/linux/rbtree.h
@@ -145,6 +145,9 @@ extern struct rb_node *rb_prev(const str
extern struct rb_node *rb_first(const struct rb_root *);
extern struct rb_node *rb_last(const struct rb_root *);
+#define rb_for_each(nd, root) \
+ for (nd = rb_first((root)); nd; nd = rb_next(nd))
+
/* Fast replacement of a single node without remove/rebalance/add/rebalance */
extern void rb_replace_node(struct rb_node *victim, struct rb_node *new,
struct rb_root *root);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [rfc -tip] lib,rb-tree - introduce rb_for_each helper
2009-07-11 22:00 [rfc -tip] lib,rb-tree - introduce rb_for_each helper Cyrill Gorcunov
@ 2009-07-11 22:29 ` Frederic Weisbecker
2009-07-11 22:32 ` Frederic Weisbecker
2009-07-12 13:20 ` Peter Zijlstra
0 siblings, 2 replies; 5+ messages in thread
From: Frederic Weisbecker @ 2009-07-11 22:29 UTC (permalink / raw)
To: Cyrill Gorcunov; +Cc: Ingo Molnar, LKML, Peter Zijlstra
On Sun, Jul 12, 2009 at 02:00:09AM +0400, Cyrill Gorcunov wrote:
> perftools already use a number of opencoded
> for() iterators over rbtree. The patch introduce
> rb_for_each helper for this purpose.
>
> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
> ---
>
> The real conversion for this macro usage should be
> done later.
>
> Also I think having rb_for_each_entry for being used
> with container_of inbetween could be convinient as
> well.
>
> Anyway if we don't need such a helper -- just drop
> the patch.
>
> include/linux/rbtree.h | 3 +++
> 1 file changed, 3 insertions(+)
>
> Index: linux-2.6.git/include/linux/rbtree.h
> =====================================================================
> --- linux-2.6.git.orig/include/linux/rbtree.h
> +++ linux-2.6.git/include/linux/rbtree.h
> @@ -145,6 +145,9 @@ extern struct rb_node *rb_prev(const str
> extern struct rb_node *rb_first(const struct rb_root *);
> extern struct rb_node *rb_last(const struct rb_root *);
>
> +#define rb_for_each(nd, root) \
> + for (nd = rb_first((root)); nd; nd = rb_next(nd))
> +
> /* Fast replacement of a single node without remove/rebalance/add/rebalance */
> extern void rb_replace_node(struct rb_node *victim, struct rb_node *new,
> struct rb_root *root);
Nice idea!
This pattern is often taken in perfcounter tools.
Also to complete this pattern, an abstract container retrieval
would be also useful as an iterator:
#define rb_for_each_entry(tpos, pos, root, memb) \
for (pos = rb_first(root); pos && tpos = rb_entry(pos, typeof(*tpos), memb); \
pos = rb_next(pos->memb, typeof(*pos), memb))
Or something like that...
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [rfc -tip] lib,rb-tree - introduce rb_for_each helper
2009-07-11 22:29 ` Frederic Weisbecker
@ 2009-07-11 22:32 ` Frederic Weisbecker
2009-07-12 5:39 ` Cyrill Gorcunov
2009-07-12 13:20 ` Peter Zijlstra
1 sibling, 1 reply; 5+ messages in thread
From: Frederic Weisbecker @ 2009-07-11 22:32 UTC (permalink / raw)
To: Cyrill Gorcunov; +Cc: Ingo Molnar, LKML, Peter Zijlstra
On Sun, Jul 12, 2009 at 12:29:30AM +0200, Frederic Weisbecker wrote:
> pos = rb_next(pos->memb, typeof(*pos), memb))
pos = rb_next(pos) would suffice :)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [rfc -tip] lib,rb-tree - introduce rb_for_each helper
2009-07-11 22:32 ` Frederic Weisbecker
@ 2009-07-12 5:39 ` Cyrill Gorcunov
0 siblings, 0 replies; 5+ messages in thread
From: Cyrill Gorcunov @ 2009-07-12 5:39 UTC (permalink / raw)
To: Frederic Weisbecker; +Cc: Ingo Molnar, LKML, Peter Zijlstra
[Frederic Weisbecker - Sun, Jul 12, 2009 at 12:32:33AM +0200]
| On Sun, Jul 12, 2009 at 12:29:30AM +0200, Frederic Weisbecker wrote:
| > pos = rb_next(pos->memb, typeof(*pos), memb))
|
| pos = rb_next(pos) would suffice :)
|
Hi Frederic,
mind to pick the patch up and complete it with
rb_for_each_entry as well? ;)
-- Cyrill
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [rfc -tip] lib,rb-tree - introduce rb_for_each helper
2009-07-11 22:29 ` Frederic Weisbecker
2009-07-11 22:32 ` Frederic Weisbecker
@ 2009-07-12 13:20 ` Peter Zijlstra
1 sibling, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2009-07-12 13:20 UTC (permalink / raw)
To: Frederic Weisbecker; +Cc: Cyrill Gorcunov, Ingo Molnar, LKML
On Sun, 2009-07-12 at 00:29 +0200, Frederic Weisbecker wrote:
> #define rb_for_each_entry(tpos, pos, root, memb) \
> for (pos = rb_first(root); pos && tpos = rb_entry(pos, typeof(*tpos), memb); \
> pos = rb_next(pos->memb, typeof(*pos), memb))
if you really want to do this, then at least call it:
for_each_rb_entry().
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-07-12 13:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-11 22:00 [rfc -tip] lib,rb-tree - introduce rb_for_each helper Cyrill Gorcunov
2009-07-11 22:29 ` Frederic Weisbecker
2009-07-11 22:32 ` Frederic Weisbecker
2009-07-12 5:39 ` Cyrill Gorcunov
2009-07-12 13:20 ` Peter Zijlstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox