From cd47f515cfd436cf170e0f6a95d659d0636e04f9 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 24 Feb 2014 16:40:29 +0300 Subject: [PATCH] avl: introduce avl_clone() This is like slist_clone(). Perhaps I should have named it stree_clone()? I will fix up the naming later. Signed-off-by: Dan Carpenter --- avl.c | 11 +++++++++++ avl.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/avl.c b/avl.c index ab270992..16b686cd 100644 --- a/avl.c +++ b/avl.c @@ -448,3 +448,14 @@ void avl_iter_next(AvlIter *iter) iter->node = node; iter->sm = (struct sm_state *) node->sm; } + +AVL *avl_clone(AVL *orig) +{ + AVL *new = NULL; + AvlIter i; + + avl_foreach(i, orig) + avl_insert(&new, i.sm); + + return new; +} diff --git a/avl.h b/avl.h index dfbfeedd..ff4c087f 100644 --- a/avl.h +++ b/avl.h @@ -116,4 +116,6 @@ struct AvlNode { AvlNode *avl_lookup_node(const AVL *avl, const struct sm_state *sm); /* O(log n). Lookup an AVL node by sm. Return NULL if not present. */ +AVL *avl_clone(AVL *orig); + #endif -- 2.11.4.GIT