tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

rfc: rb tree helper macros



Hi,

I have a couple of macros which generally simplify traversal thgough rb
trees.

diff --git a/sys/sys/rb.h b/sys/sys/rb.h
index 7448247..59d9e72 100644
--- a/sys/sys/rb.h
+++ b/sys/sys/rb.h
@@ -169,4 +169,17 @@ void       rb_tree_check(const struct rb_tree *, bool);
 void   rb_tree_depths(const struct rb_tree *, size_t *);
 #endif
 
+#define RB_TREE_MIN(T) rb_tree_iterate((T), NULL, RB_DIR_LEFT)
+#define RB_TREE_MAX(T) rb_tree_iterate((T), NULL, RB_DIR_RIGHT)
+#define RB_TREE_FOREACH(N, T)                                       \
+       for (                                                       \
+                       N = RB_TREE_MIN(T); N;                      \
+                       N = rb_tree_iterate((T), (N), RB_DIR_RIGHT) \
+           )
+#define RB_TREE_FOREACH_REVERSE(N, T)                               \
+       for (                                                       \
+                       N = RB_TREE_MAX(T); N;                      \
+                       N = rb_tree_iterate((T), (N), RB_DIR_LEFT)  \
+           )
+
 #endif /* _SYS_RB_H_*/

Regards,
--
Alex


Home | Main Index | Thread Index | Old Index