aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-07-13 08:03:20 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-07-13 08:03:20 +0200
commit3b313daec1614d8a3288b8e20a06dc912a59bda8 (patch)
tree9b4ade371c2c021c905f8abe38503f7f910d3764 /test
parent4abb81c230bfcd599ccceb2b1bcbdcadbd859537 (diff)
downloadnissy-core-3b313daec1614d8a3288b8e20a06dc912a59bda8.tar.gz
nissy-core-3b313daec1614d8a3288b8e20a06dc912a59bda8.zip
Added a set implementation for h48 table generation
Diffstat (limited to 'test')
-rw-r--r--test/104_h48set/00_small.in6
-rw-r--r--test/104_h48set/00_small.out3
-rw-r--r--test/104_h48set/01_large.in153
-rw-r--r--test/104_h48set/01_large.out83
-rw-r--r--test/104_h48set/h48set_tests.c69
5 files changed, 314 insertions, 0 deletions
diff --git a/test/104_h48set/00_small.in b/test/104_h48set/00_small.in
new file mode 100644
index 0000000..d788d5b
--- /dev/null
+++ b/test/104_h48set/00_small.in
@@ -0,0 +1,6 @@
111
27
33
434
545
634
diff --git a/test/104_h48set/00_small.out b/test/104_h48set/00_small.out
new file mode 100644
index 0000000..29c08e5
--- /dev/null
+++ b/test/104_h48set/00_small.out
@@ -0,0 +1,3 @@
12
234
345
diff --git a/test/104_h48set/01_large.in b/test/104_h48set/01_large.in
new file mode 100644
index 0000000..a70ef9a
--- /dev/null
+++ b/test/104_h48set/01_large.in
@@ -0,0 +1,153 @@
1307
2293
3150
4100053
5100045
6100007
7100007
8100011
9100072
10100033
11100015
12100013
13100068
14100047
15100046
16100000
17100076
18100021
19100019
20100015
21100049
22100052
23100071
24100058
25100009
26100060
27100030
28100051
29100069
30100011
31100051
32100014
33100031
34100017
35100076
36100016
37100030
38100037
39100011
40100002
41100029
42100022
43100038
44100075
45100066
46100051
47100020
48100039
49100029
50100087
51100099
52100041
53100042
54100026
55100060
56100006
57100010
58100079
59100046
60100086
61100010
62100036
63100047
64100069
65100041
66100074
67100090
68100092
69100020
70100096
71100046
72100028
73100072
74100096
75100025
76100001
77100067
78100044
79100063
80100026
81100062
82100091
83100012
84100073
85100051
86100010
87100096
88100043
89100025
90100077
91100089
92100005
93100024
94100091
95100046
96100053
97100058
98100065
99100051
100100056
101100025
102100093
103100088
104100033
105100073
106100048
107100059
108100027
109100045
110100012
111100059
112100084
113100017
114100048
115100004
116100051
117100016
118100088
119100033
120100064
121100060
122100043
123100084
124100026
125100051
126100060
127100069
128100015
129100014
130100038
131100068
132100038
133100097
134100017
135100013
136100053
137100019
138100018
139100081
140100071
141100025
142100014
143100016
144100011
145100069
146100079
147100063
148100070
149100072
150100095
151100042
152100008
153100022
diff --git a/test/104_h48set/01_large.out b/test/104_h48set/01_large.out
new file mode 100644
index 0000000..6632336
--- /dev/null
+++ b/test/104_h48set/01_large.out
@@ -0,0 +1,83 @@
182
2100000
3100001
4100002
5100004
6100005
7100006
8100007
9100008
10100009
11100010
12100011
13100012
14100013
15100014
16100015
17100016
18100017
19100018
20100019
21100020
22100021
23100022
24100024
25100025
26100026
27100027
28100028
29100029
30100030
31100031
32100033
33100036
34100037
35100038
36100039
37100041
38100042
39100043
40100044
41100045
42100046
43100047
44100048
45100049
46100051
47100052
48100053
49100056
50100058
51100059
52100060
53100062
54100063
55100064
56100065
57100066
58100067
59100068
60100069
61100070
62100071
63100072
64100073
65100074
66100075
67100076
68100077
69100079
70100081
71100084
72100086
73100087
74100088
75100089
76100090
77100091
78100092
79100093
80100095
81100096
82100097
83100099
diff --git a/test/104_h48set/h48set_tests.c b/test/104_h48set/h48set_tests.c
new file mode 100644
index 0000000..97811da
--- /dev/null
+++ b/test/104_h48set/h48set_tests.c
@@ -0,0 +1,69 @@
1#include "../test.h"
2
3char str[STRLENMAX];
4
5typedef struct {
6 int64_t n;
7 int64_t capacity;
8 int64_t mod;
9 int64_t *table;
10} h48set_t;
11
12void h48set_create(h48set_t *, int64_t, int64_t);
13void h48set_clear(h48set_t *);
14void h48set_destroy(h48set_t *);
15int64_t h48set_lookup(h48set_t *, int64_t);
16void h48set_insert(h48set_t *, int64_t);
17bool h48set_contains(h48set_t *, int64_t);
18
19int compare(const void *x, const void *y) {
20 int64_t a = *(int64_t *)x;
21 int64_t b = *(int64_t *)y;
22
23 if (a > b) return 1;
24 if (a == b) return 0;
25 return -1;
26}
27
28int64_t readl(void) {
29 fgets(str, STRLENMAX, stdin);
30 return atoll(str);
31}
32
33void run(void) {
34 bool f;
35 h48set_t set;
36 int64_t n, i, j, capacity, mod, *a, u;
37
38 capacity = readl();
39 mod = readl();
40 n = readl();
41
42 a = malloc(n * sizeof(int64_t));
43 for (i = 0; i < n; i++)
44 a[i] = readl();
45
46 /* Count unique elements */
47 u = 0;
48 for (i = 0; i < n; i++) {
49 for (j = 0, f = true; j < i; j++)
50 f = f && a[i] != a[j];
51 u += f;
52 }
53
54 h48set_create(&set, capacity, mod);
55 for (i = 0; i < n; i++)
56 h48set_insert(&set, a[i]);
57
58 for (i = 0, j = 0; i < set.capacity; i++)
59 if (set.table[i] != -1)
60 a[j++] = set.table[i];
61 qsort(a, j, sizeof(int64_t), compare);
62
63 printf("%" PRId64 "\n", set.n);
64 for (i = 0; i < j; i++)
65 printf("%" PRId64 "\n", a[i]);
66
67 h48set_destroy(&set);
68 free(a);
69}

Generated with cgit - Back to sebastiano.tronto.net