From db396e6ede3b36ca1887450d8959de35b38d1ea7 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sun, 3 Jan 2021 16:58:48 -0500 Subject: Add function to recalculate length (weights) of rope nodes (Probably need a rebalance function to go along with/replace this) --- structures/rope/rope.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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; { -- cgit v1.1