aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tucker@tuckerevans.com>2020-12-31 03:20:37 -0500
committerTucker Evans <tucker@tuckerevans.com>2020-12-31 03:20:37 -0500
commite2a99fae3709a5e0fdff92c2a787cde595bdffcc (patch)
tree969080ae44196569e6cb541243e6cb08663768a7
parent435ab65d59f2a2eb1908a4b399049f6bfa0934e3 (diff)
Add function to get full length of rope
-rw-r--r--structures/rope/rope.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/structures/rope/rope.c b/structures/rope/rope.c
index e1ae4a9..f3828df 100644
--- a/structures/rope/rope.c
+++ b/structures/rope/rope.c
@@ -28,6 +28,18 @@ rope* rope_new()
return tmp;
}
+size_t rope_len(root)
+rope *root;
+{
+ if (!root)
+ return 0;
+
+ if (root->str)
+ return strlen(root->str);
+
+ return rope_len(root->left) + rope_len(root->right);
+}
+
rope* str_to_rope(str)
char *str;
{