From 4294ec0ed06ee34920c9edaeebaeb8b65c720791 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 19 Jul 2024 01:29:42 +0200 Subject: First commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libnormalform_reset_indices_and_counts__.c | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 libnormalform_reset_indices_and_counts__.c (limited to 'libnormalform_reset_indices_and_counts__.c') diff --git a/libnormalform_reset_indices_and_counts__.c b/libnormalform_reset_indices_and_counts__.c new file mode 100644 index 0000000..f6b1790 --- /dev/null +++ b/libnormalform_reset_indices_and_counts__.c @@ -0,0 +1,44 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +/** + * Undo `libnormalform_set_indices_and_counts__` + * + * This is needed because `libnormalform_set_indices_and_counts__` + * requires some otherwise unused memory to be properly initialised + * + * @param this The sentence that shall be recursively restored + */ +void +(libnormalform_reset_indices_and_counts__)(LIBNORMALFORM_SENTENCE *this) +{ + LIBNORMALFORM_SENTENCE *head = NULL; + + this->travel_count -= 1; + do { + this->travel_index = 0; + if (IS_BRANCH(this)) { + if (!--RIGHT(this)->travel_count) + PUSH(&head, RIGHT(this)); + if (!--LEFT(this)->travel_count) + PUSH(&head, LEFT(this)); + } + } while (POP(&head, &this)); + +#undef UNMARK +} + + +#else + + +CONST int +main(void) +{ + return 0; /* indirectly tested */ +} + + +#endif -- cgit v1.3.1