diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2020-12-31 03:21:27 -0500 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2020-12-31 03:21:27 -0500 |
commit | a877aba402d5087d8fdb3a4e8ae7462656ca9589 (patch) | |
tree | b9b6ecfef1db0690b3a3c250fdf00aae8615fe48 | |
parent | e2a99fae3709a5e0fdff92c2a787cde595bdffcc (diff) |
Add concat function for ropes
-rw-r--r-- | structures/rope/rope.c | 17 | ||||
-rw-r--r-- | structures/rope/rope.h | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/structures/rope/rope.c b/structures/rope/rope.c index f3828df..50c7fef 100644 --- a/structures/rope/rope.c +++ b/structures/rope/rope.c @@ -55,3 +55,20 @@ char *str; return tmp; } +rope* rope_concat(node1, node2) +rope *node1, *node2; +{ + rope *tmp; + + if (!node1 || !node2) + return node1 ? node1 : node2; + + tmp = rope_new(); + tmp->len = rope_len(node1); + tmp->left = node1; + tmp->right = node2; + node1->parent = tmp; + node2->parent = tmp; + + return tmp; +} diff --git a/structures/rope/rope.h b/structures/rope/rope.h index 80e60a3..f012cc1 100644 --- a/structures/rope/rope.h +++ b/structures/rope/rope.h @@ -5,5 +5,6 @@ typede struct rope_s rope; rope* rope_new(); rope* str_to_rope(char*); +rope* rope_concate(rope*, rope*); #endif |