aboutsummaryrefslogtreecommitdiffstats
path: root/libnormalform_set_indices_and_counts__.c
blob: 2dbc9aa98a8b0893a241b82866a4bb75ab8bb2a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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