aboutsummaryrefslogtreecommitdiff
path: root/test/112_h48map
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-07-18 11:09:50 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-07-18 11:09:50 +0200
commit7946c8efc2e2a44a8e78e1263c1691ce9f412a09 (patch)
treef04505d6444a59b26c8c2e55311b70bbbf1ce364 /test/112_h48map
parent3d060c348fdfff074a9b902d56f539664789d831 (diff)
downloadnissy-core-7946c8efc2e2a44a8e78e1263c1691ce9f412a09.tar.gz
nissy-core-7946c8efc2e2a44a8e78e1263c1691ce9f412a09.zip
Converted set to map
Diffstat (limited to 'test/112_h48map')
-rw-r--r--test/112_h48map/00_small.in11
-rw-r--r--test/112_h48map/00_small.out3
-rw-r--r--test/112_h48map/01_large.in303
-rw-r--r--test/112_h48map/01_large.out83
-rw-r--r--test/112_h48map/h48map_tests.c88
5 files changed, 488 insertions, 0 deletions
diff --git a/test/112_h48map/00_small.in b/test/112_h48map/00_small.in
new file mode 100644
index 0000000..ee8e591
--- /dev/null
+++ b/test/112_h48map/00_small.in
@@ -0,0 +1,11 @@
111
27
34
434
512
645
77
834
913
1045
115
diff --git a/test/112_h48map/00_small.out b/test/112_h48map/00_small.out
new file mode 100644
index 0000000..260e804
--- /dev/null
+++ b/test/112_h48map/00_small.out
@@ -0,0 +1,3 @@
12
234 12
345 5
diff --git a/test/112_h48map/01_large.in b/test/112_h48map/01_large.in
new file mode 100644
index 0000000..1812b40
--- /dev/null
+++ b/test/112_h48map/01_large.in
@@ -0,0 +1,303 @@
1307
2293
3150
4100053
5417
6100045
7164
8100007
9235
10100007
11207
12100011
13406
14100072
1529
16100033
17188
18100015
19358
20100013
21248
22100068
23218
24100047
25398
26100046
27263
28100000
29471
30100076
31219
32100021
33115
34100019
35329
36100015
37178
38100049
3959
40100052
41319
42100071
43232
44100058
45174
46100009
4746
48100060
49349
50100030
51287
52100051
53203
54100069
55359
56100011
57296
58100051
59223
60100014
61233
62100031
63264
64100017
65180
66100076
6722
68100016
69213
70100030
7155
72100037
733
74100011
75467
76100002
77165
78100029
79161
80100022
8167
82100038
83374
84100075
854
86100066
87156
88100051
89144
90100020
91480
92100039
93265
94100029
95195
96100087
97245
98100099
99287
100100041
101308
102100042
10332
104100026
105312
106100060
107434
108100006
109392
110100010
111269
112100079
113414
114100046
115161
116100086
117139
118100010
11988
120100036
121117
122100047
123376
124100069
12517
126100041
127314
128100074
129320
130100090
131225
132100092
133424
134100020
135325
136100096
137318
138100046
139238
140100028
14113
142100072
14373
144100096
145262
146100025
14782
148100001
149107
150100067
151410
152100044
153449
154100063
155276
156100026
157392
158100062
159407
160100091
161411
162100012
163400
164100073
165331
166100051
16783
168100010
169385
170100096
171484
172100043
173352
174100025
175207
176100077
177272
178100089
179192
180100005
181291
182100024
183243
184100091
185445
186100046
187162
188100053
189380
190100058
191157
192100065
193464
194100051
195306
196100056
197236
198100025
199198
200100093
201230
202100088
203494
204100033
20570
206100073
207218
208100048
209486
210100059
21177
212100027
213142
214100045
215418
216100012
21768
218100059
219448
220100084
221339
222100017
22339
224100048
22583
226100004
227321
228100051
229441
230100016
231308
232100088
233334
234100033
235476
236100064
23751
238100060
239324
240100043
241149
242100084
243116
244100026
245351
246100051
247396
248100060
249377
250100069
251301
252100015
253319
254100014
255466
256100038
257194
258100068
25941
260100038
261295
262100097
263394
264100017
26534
266100013
267223
268100053
269339
270100019
27167
272100018
27324
274100081
275205
276100071
277440
278100025
279228
280100014
281169
282100016
283121
284100011
285444
286100069
287460
288100079
289139
290100063
291169
292100070
293132
294100072
295119
296100095
297126
298100042
299217
300100008
301272
302100022
303121
diff --git a/test/112_h48map/01_large.out b/test/112_h48map/01_large.out
new file mode 100644
index 0000000..f5e00d8
--- /dev/null
+++ b/test/112_h48map/01_large.out
@@ -0,0 +1,83 @@
182
2100000 471
3100001 107
4100002 165
5100004 321
6100005 291
7100006 392
8100007 207
9100008 272
10100009 46
11100010 88
12100011 296
13100012 68
14100013 223
15100014 169
16100015 178
17100016 121
18100017 34
19100018 24
20100019 67
21100020 325
22100021 115
23100022 67
24100024 243
25100025 82
26100026 312
27100027 142
28100028 13
29100029 161
30100030 55
31100031 264
32100033 70
33100036 117
34100037 3
35100038 194
36100039 265
37100041 308
38100042 32
39100043 149
40100044 449
41100045 164
42100046 161
43100047 376
44100048 83
45100049 59
46100051 83
47100052 319
48100053 339
49100056 236
50100058 157
51100059 77
52100060 324
53100062 407
54100063 169
55100064 51
56100065 464
57100066 156
58100067 410
59100068 41
60100069 17
61100070 132
62100071 232
63100072 29
64100073 218
65100074 320
66100075 4
67100076 22
68100077 272
69100079 139
70100081 205
71100084 116
72100086 139
73100087 245
74100088 334
75100089 192
76100090 225
77100091 411
78100092 424
79100093 230
80100095 126
81100096 262
82100097 394
83100099 287
diff --git a/test/112_h48map/h48map_tests.c b/test/112_h48map/h48map_tests.c
new file mode 100644
index 0000000..ce8f657
--- /dev/null
+++ b/test/112_h48map/h48map_tests.c
@@ -0,0 +1,88 @@
1#include "../test.h"
2
3#define MAP_KEYSHIFT UINT64_C(40)
4
5typedef struct {
6 uint64_t n;
7 uint64_t capacity;
8 uint64_t mod;
9 uint64_t *table;
10} h48map_t;
11
12typedef struct {
13 uint64_t key;
14 uint64_t val;
15} kvpair_t;
16
17void h48map_create(h48map_t *, uint64_t, uint64_t);
18void h48map_clear(h48map_t *);
19void h48map_destroy(h48map_t *);
20uint64_t h48map_lookup(h48map_t *, uint64_t);
21void h48map_insertmin(h48map_t *, uint64_t, uint64_t);
22uint64_t h48map_value(h48map_t *, uint64_t);
23kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *);
24
25char str[STRLENMAX];
26
27int compare(const void *x, const void *y) {
28 uint64_t a = ((kvpair_t *)x)->key;
29 uint64_t b = ((kvpair_t *)y)->key;
30
31 if (a > b) return 1;
32 if (a == b) return 0;
33 return -1;
34}
35
36uint64_t readl(void) {
37 fgets(str, STRLENMAX, stdin);
38 return atoll(str);
39}
40
41void run(void) {
42 h48map_t map;
43 uint64_t n, i, j, capacity, mod, x, y, v;
44 kvpair_t kv, *a, *b;
45
46 capacity = readl();
47 mod = readl();
48 n = readl();
49
50 a = malloc(n * sizeof(kvpair_t));
51 b = malloc(n * sizeof(kvpair_t));
52 for (i = 0; i < n; i++) {
53 x = readl();
54 y = readl();
55 a[i] = (kvpair_t) { .key = x, .val = y };
56 }
57
58 h48map_create(&map, capacity, mod);
59 for (i = 0; i < n; i++)
60 h48map_insertmin(&map, a[i].key, a[i].val);
61
62 i = 0;
63 for (kv = h48map_nextkvpair(&map, &i), j = 0;
64 i != map.capacity;
65 kv = h48map_nextkvpair(&map, &i)
66 ) {
67 b[j++] = kv;
68 }
69 qsort(b, j, sizeof(kvpair_t), compare);
70
71 printf("%" PRIu64 "\n", map.n);
72 for (i = 0; i < j; i++)
73 printf("%" PRIu64 " %" PRIu64 "\n", b[i].key, b[i].val);
74 if (map.n != j)
75 printf("Wrong number of elements: map->n = %" PRIu64 ", "
76 "but scan returns %" PRIu64 "\n", map.n, j);
77 for (i = 0; i < n; i++) {
78 v = h48map_value(&map, a[i].key);
79 if (v > a[i].val)
80 printf("Value for key %" PRId64 " is larger than "
81 "expected (%" PRIu64 " > %" PRIu64 ")\n",
82 a[i].key, v, a[i].val);
83 }
84
85 h48map_destroy(&map);
86 free(a);
87 free(b);
88}

Generated with cgit - Back to sebastiano.tronto.net