diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2021-01-03 16:58:48 -0500 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2021-01-03 16:58:48 -0500 |
commit | db396e6ede3b36ca1887450d8959de35b38d1ea7 (patch) | |
tree | b032190763229f301f4fee88fc4a7d91c0457ea0 | |
parent | 0ee6aa96f6ea3fe1a1eb855aed5d6c466643878a (diff) |
Add function to recalculate length (weights) of rope nodes
(Probably need a rebalance function to go along with/replace this)
-rw-r--r-- | structures/rope/rope.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/structures/rope/rope.c b/structures/rope/rope.c index aed104b..1f0a389 100644 --- a/structures/rope/rope.c +++ b/structures/rope/rope.c @@ -82,11 +82,23 @@ rope *root; return 0; if (root->str) - return strlen(root->str); + return root->len; return rope_len(root->left) + rope_len(root->right); } +size_t rope_relen(root) +rope *root; +{ + if (!root) + return 0; + + if (root->str) + return root->len; + + return root->len = rope_relen(root->left) + rope_len(root->right); +} + rope* str_to_rope(str) char *str; { |