diff options
Diffstat (limited to 'libnormalform_reset_indices_and_counts__.c')
| -rw-r--r-- | libnormalform_reset_indices_and_counts__.c | 44 |
1 files changed, 44 insertions, 0 deletions
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 |
