diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2021-01-03 16:58:24 -0500 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2021-01-03 16:58:24 -0500 |
commit | 0ee6aa96f6ea3fe1a1eb855aed5d6c466643878a (patch) | |
tree | 2baf91211e9015b3629515dff92ecc9a73ad9ffa | |
parent | a877aba402d5087d8fdb3a4e8ae7462656ca9589 (diff) |
Add debug/print functions for rope
-rw-r--r-- | structures/rope/rope.c | 47 | ||||
-rw-r--r-- | structures/rope/rope.h | 2 |
2 files changed, 48 insertions, 1 deletions
diff --git a/structures/rope/rope.c b/structures/rope/rope.c index 50c7fef..aed104b 100644 --- a/structures/rope/rope.c +++ b/structures/rope/rope.c @@ -28,6 +28,53 @@ rope* rope_new() return tmp; } +void rope_debug_print_aux(root, s) +rope *root; +int s; +{ + int i; + + for (i = 0; i < s; i++) + printf("| "); + + if (!root) { + printf("\n"); + return; + } + +#ifdef ROPE_DEBUG_PARENT + printf("[%p]\n", root->parent); +#endif + + printf("{len:%d,str:\'%s\'}[%p]\n", root->len, root->str, root); + + if (root->str) + return; + + rope_debug_print_aux(root->left, ++s); + rope_debug_print_aux(root->right, s); + +} + +void rope_debug_print(root) +rope *root; +{ + rope_debug_print_aux(root, 0); +} + +void rope_print(root) +rope *root; +{ + if (!root) + return; + + if (root->str) + printf("%s", root->str); + + rope_print(root->left); + rope_print(root->right); +} + size_t rope_len(root) rope *root; { diff --git a/structures/rope/rope.h b/structures/rope/rope.h index f012cc1..86d9ae3 100644 --- a/structures/rope/rope.h +++ b/structures/rope/rope.h @@ -1,7 +1,7 @@ #ifndef ROPE_H #define ROPE_H -typede struct rope_s rope; +typedef struct rope_s rope; rope* rope_new(); rope* str_to_rope(char*); |