[sheepdog] [PATCH v3 03/11] rbtree: add rb_copy helper

Liu Yuan namei.unix at gmail.com
Sat Sep 21 18:12:20 CEST 2013


Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 include/rbtree.h |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/rbtree.h b/include/rbtree.h
index 07b6fe6..7dbc39e 100644
--- a/include/rbtree.h
+++ b/include/rbtree.h
@@ -185,4 +185,15 @@ static inline void rb_link_node(struct rb_node *node, struct rb_node *parent,
         }                                                               \
 }
 
+/* Copy the tree 'root' as 'outroot' */
+#define rb_copy(root, type, member, outroot, compar)                    \
+{                                                                       \
+        type *__p, *__n3;                                               \
+        rb_for_each_entry(__p, root, member) {                          \
+                __n3 = xmalloc(sizeof(*__n3));                          \
+                *__n3 = *__p;                                           \
+                rb_insert(outroot, __n3, member, compar);               \
+        }                                                               \
+}
+
 #endif /* __RBTREE_H_ */
-- 
1.7.9.5




More information about the sheepdog mailing list