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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
#include <stdio.h>
#include "../util.h"
#include "../crf.h"
int
main(int UNUSED argc, char ** UNUSED argv)
{
procr *pr = NULL;
procu *pu = NULL;
spa *spap = NULL;
prodecor *prod = NULL;
/* check crf */
crf *crfp = new_crf();
pair2 p = { 0 };
p.x = 0;
p.y = 1;
if (crf_find_node(crfp, p) == NULL) {
if (crf_add_node(crfp, p)) {
fleprintf0("fail to add node\n");
goto cleanup;
} else {
printf("Successfully add node (0, 1)\n");
}
}
if (crf_find_node(crfp, p) == NULL) {
fleprintf0("Fail to find node\n");
goto cleanup;
} else {
printf("Successfully find node for (0, 1)\n");
}
pair4 p4 = { 0 };
if (crf_add_edge(crfp, p, p4)) {
fleprintf0("Fail to add edge\n");
goto cleanup;
} else {
printf("Successfully add edge from (0, 1) to zero\n");
}
if (crf_find_node(crfp, p)) {
printf("Printing edges for (0, 1)...\n");
#define TABLE (crf_find_node(crfp, p))
for (NUM i = 0; i < ht_size(TABLE); i++) {
#define KEY (*((pair4**) ht_keys(TABLE)+i))
printf("(%ld, %ld, %ld, %ld)",
KEY->x, KEY->y, KEY->z, KEY->w);
if (i+1<ht_size(TABLE)) printf(", ");
else printf("\n");
}
}
#undef TABLE
#undef KEY
/* check spa */
spap = new_spa();
if (spap == NULL) {
fleprintf0("fail to have new spa\n");
goto cleanup;
}
pair3 p3 = (pair3) { 0 };
p3.x = 0;
p3.y = 1;
p3.z = 10;
if (spa_insert(spap, p3)) {
fleprintf0("Fail to insert\n");
goto cleanup;
}
printf("Successfully inserted into SPA\n");
if (spa_belong(spap, p3)) {
printf("Successfully found p3\n");
} else {
fleprintf0("Fail to find p3\n");
goto cleanup;
}
pair2 first_two = (pair2) { 0 };
first_two.x = 0;
first_two.y = 1;
if (spa_find(spap, first_two)) {
printf("Successfully found p2\n");
} else {
fleprintf0("Fail to find p2\n");
goto cleanup;
}
/* check prodecor */
BOOL error = 0;
pr = new_procr(10, &error);
pu = new_procu(10, &error);
p4 = (pair4) { 0 };
p4.x = 1;
if (desc_add(pr, pu, 2, p4)) {
fleprintf0("Fail to add descriptor\n");
goto cleanup;
}
NUM grade = 0;
prod = pop_procr(pr, pu, &grade);
if (prod == NULL) {
printf("The first pop failed. "
"But maybe it occurs due to some misses in the minimal "
"weight.\n");
printf("So we shall pop again\n");
prod = pop_procr(pr, pu, &grade);
if (prod == NULL) {
fleprintf0("Fail to pop\n");
goto cleanup;
}
}
printf("popped a process descriptor: (%ld, %ld, %ld, %ld, %ld)\n",
prod->x, prod->y, prod->z, prod->w, grade);
cleanup:
destroy_crf(crfp);
if (pr) destroy_procr(pr);
if (pu) destroy_procu(pu);
if (spap) destroy_spa(spap);
if (prod) free(prod);
return 0;
}
|