rbtree
diff src/rbtree.c @ 5:56a08d00bb41
added rb_copy and rb_clear
moved the visualization test to test/vis/
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 12 Oct 2011 05:25:34 +0300 |
parents | 53afe96233f2 |
children | 2c0baa1fd419 |
line diff
1.1 --- a/src/rbtree.c Wed Oct 12 05:01:11 2011 +0300 1.2 +++ b/src/rbtree.c Wed Oct 12 05:25:34 2011 +0300 1.3 @@ -90,6 +90,27 @@ 1.4 rb->del_cls = cls; 1.5 } 1.6 1.7 + 1.8 +void rb_clear(struct rbtree *rb) 1.9 +{ 1.10 + del_tree(rb->root, rb->del, rb->del_cls); 1.11 + rb->root = 0; 1.12 +} 1.13 + 1.14 +int rb_copy(struct rbtree *dest, struct rbtree *src) 1.15 +{ 1.16 + struct rbnode *node; 1.17 + 1.18 + rb_clear(dest); 1.19 + rb_begin(src); 1.20 + while((node = rb_next(src))) { 1.21 + if(rb_insert(dest, node->key, node->data) == -1) { 1.22 + return -1; 1.23 + } 1.24 + } 1.25 + return 0; 1.26 +} 1.27 + 1.28 int rb_size(struct rbtree *rb) 1.29 { 1.30 return count_nodes(rb->root);