aboutsummaryrefslogtreecommitdiffstats
path: root/libnormalform_set_indices_and_counts__.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnormalform_set_indices_and_counts__.c')
-rw-r--r--libnormalform_set_indices_and_counts__.c56
1 files changed, 56 insertions, 0 deletions
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