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_set_indices_and_counts__.c | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 libnormalform_set_indices_and_counts__.c (limited to 'libnormalform_set_indices_and_counts__.c') diff --git a/libnormalform_set_indices_and_counts__.c b/libnormalform_set_indices_and_counts__.c new file mode 100644 index 0000000..2dbc9aa --- /dev/null +++ b/libnormalform_set_indices_and_counts__.c @@ -0,0 +1,56 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifndef TEST + + +/** + * Annotate every sentence that appear multiple times + * with a unique index (counted from 0 up) + * + * @param this The sentence that shall be inspected + * recursively for annotation + * @return The number of annotated sentences + */ +size_t +(libnormalform_set_indices_and_counts__)(LIBNORMALFORM_SENTENCE *this) +{ + LIBNORMALFORM_SENTENCE *head = NULL, *a, *b; + size_t count = 0; + + this->travel_count = 1; + do { + if (IS_BRANCH(this)) { + a = LEFT(this); + b = RIGHT(this); + + a->travel_count += 1; + if (a->travel_count == 2) + a->travel_index = count++; + + b->travel_count += 1; + if (b->travel_count == 2) + b->travel_index = count++; + + if (b->travel_count == 1) + PUSH(&head, b); + + if (a->travel_count == 1) + PUSH(&head, a); + } + } while (POP(&head, &this)); + + return count; +} + + +#else + + +CONST int +main(void) +{ + return 0; /* indirectly tested */ +} + + +#endif -- cgit v1.3.1