diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-18 11:09:50 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-18 11:09:50 +0200 |
| commit | 7946c8efc2e2a44a8e78e1263c1691ce9f412a09 (patch) | |
| tree | f04505d6444a59b26c8c2e55311b70bbbf1ce364 /test | |
| parent | 3d060c348fdfff074a9b902d56f539664789d831 (diff) | |
| download | nissy-core-7946c8efc2e2a44a8e78e1263c1691ce9f412a09.tar.gz nissy-core-7946c8efc2e2a44a8e78e1263c1691ce9f412a09.zip | |
Converted set to map
Diffstat (limited to 'test')
| -rw-r--r-- | test/112_h48map/00_small.in | 11 | ||||
| -rw-r--r-- | test/112_h48map/00_small.out | 3 | ||||
| -rw-r--r-- | test/112_h48map/01_large.in (renamed from test/112_h48set/01_large.in) | 150 | ||||
| -rw-r--r-- | test/112_h48map/01_large.out | 83 | ||||
| -rw-r--r-- | test/112_h48map/h48map_tests.c | 88 | ||||
| -rw-r--r-- | test/112_h48set/00_small.in | 6 | ||||
| -rw-r--r-- | test/112_h48set/00_small.out | 3 | ||||
| -rw-r--r-- | test/112_h48set/01_large.out | 83 | ||||
| -rw-r--r-- | test/112_h48set/h48set_tests.c | 64 |
9 files changed, 335 insertions, 156 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 @@ | |||
| 1 | 11 | ||
| 2 | 7 | ||
| 3 | 4 | ||
| 4 | 34 | ||
| 5 | 12 | ||
| 6 | 45 | ||
| 7 | 7 | ||
| 8 | 34 | ||
| 9 | 13 | ||
| 10 | 45 | ||
| 11 | 5 | ||
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 @@ | |||
| 1 | 2 | ||
| 2 | 34 12 | ||
| 3 | 45 5 | ||
diff --git a/test/112_h48set/01_large.in b/test/112_h48map/01_large.in index a70ef9a..1812b40 100644 --- a/test/112_h48set/01_large.in +++ b/test/112_h48map/01_large.in | |||
| @@ -2,152 +2,302 @@ | |||
| 2 | 293 | 2 | 293 |
| 3 | 150 | 3 | 150 |
| 4 | 100053 | 4 | 100053 |
| 5 | 417 | ||
| 5 | 100045 | 6 | 100045 |
| 7 | 164 | ||
| 6 | 100007 | 8 | 100007 |
| 9 | 235 | ||
| 7 | 100007 | 10 | 100007 |
| 11 | 207 | ||
| 8 | 100011 | 12 | 100011 |
| 13 | 406 | ||
| 9 | 100072 | 14 | 100072 |
| 15 | 29 | ||
| 10 | 100033 | 16 | 100033 |
| 17 | 188 | ||
| 11 | 100015 | 18 | 100015 |
| 19 | 358 | ||
| 12 | 100013 | 20 | 100013 |
| 21 | 248 | ||
| 13 | 100068 | 22 | 100068 |
| 23 | 218 | ||
| 14 | 100047 | 24 | 100047 |
| 25 | 398 | ||
| 15 | 100046 | 26 | 100046 |
| 27 | 263 | ||
| 16 | 100000 | 28 | 100000 |
| 29 | 471 | ||
| 17 | 100076 | 30 | 100076 |
| 31 | 219 | ||
| 18 | 100021 | 32 | 100021 |
| 33 | 115 | ||
| 19 | 100019 | 34 | 100019 |
| 35 | 329 | ||
| 20 | 100015 | 36 | 100015 |
| 37 | 178 | ||
| 21 | 100049 | 38 | 100049 |
| 39 | 59 | ||
| 22 | 100052 | 40 | 100052 |
| 41 | 319 | ||
| 23 | 100071 | 42 | 100071 |
| 43 | 232 | ||
| 24 | 100058 | 44 | 100058 |
| 45 | 174 | ||
| 25 | 100009 | 46 | 100009 |
| 47 | 46 | ||
| 26 | 100060 | 48 | 100060 |
| 49 | 349 | ||
| 27 | 100030 | 50 | 100030 |
| 51 | 287 | ||
| 28 | 100051 | 52 | 100051 |
| 53 | 203 | ||
| 29 | 100069 | 54 | 100069 |
| 55 | 359 | ||
| 30 | 100011 | 56 | 100011 |
| 57 | 296 | ||
| 31 | 100051 | 58 | 100051 |
| 59 | 223 | ||
| 32 | 100014 | 60 | 100014 |
| 61 | 233 | ||
| 33 | 100031 | 62 | 100031 |
| 63 | 264 | ||
| 34 | 100017 | 64 | 100017 |
| 65 | 180 | ||
| 35 | 100076 | 66 | 100076 |
| 67 | 22 | ||
| 36 | 100016 | 68 | 100016 |
| 69 | 213 | ||
| 37 | 100030 | 70 | 100030 |
| 71 | 55 | ||
| 38 | 100037 | 72 | 100037 |
| 73 | 3 | ||
| 39 | 100011 | 74 | 100011 |
| 75 | 467 | ||
| 40 | 100002 | 76 | 100002 |
| 77 | 165 | ||
| 41 | 100029 | 78 | 100029 |
| 79 | 161 | ||
| 42 | 100022 | 80 | 100022 |
| 81 | 67 | ||
| 43 | 100038 | 82 | 100038 |
| 83 | 374 | ||
| 44 | 100075 | 84 | 100075 |
| 85 | 4 | ||
| 45 | 100066 | 86 | 100066 |
| 87 | 156 | ||
| 46 | 100051 | 88 | 100051 |
| 89 | 144 | ||
| 47 | 100020 | 90 | 100020 |
| 91 | 480 | ||
| 48 | 100039 | 92 | 100039 |
| 93 | 265 | ||
| 49 | 100029 | 94 | 100029 |
| 95 | 195 | ||
| 50 | 100087 | 96 | 100087 |
| 97 | 245 | ||
| 51 | 100099 | 98 | 100099 |
| 99 | 287 | ||
| 52 | 100041 | 100 | 100041 |
| 101 | 308 | ||
| 53 | 100042 | 102 | 100042 |
| 103 | 32 | ||
| 54 | 100026 | 104 | 100026 |
| 105 | 312 | ||
| 55 | 100060 | 106 | 100060 |
| 107 | 434 | ||
| 56 | 100006 | 108 | 100006 |
| 109 | 392 | ||
| 57 | 100010 | 110 | 100010 |
| 111 | 269 | ||
| 58 | 100079 | 112 | 100079 |
| 113 | 414 | ||
| 59 | 100046 | 114 | 100046 |
| 115 | 161 | ||
| 60 | 100086 | 116 | 100086 |
| 117 | 139 | ||
| 61 | 100010 | 118 | 100010 |
| 119 | 88 | ||
| 62 | 100036 | 120 | 100036 |
| 121 | 117 | ||
| 63 | 100047 | 122 | 100047 |
| 123 | 376 | ||
| 64 | 100069 | 124 | 100069 |
| 125 | 17 | ||
| 65 | 100041 | 126 | 100041 |
| 127 | 314 | ||
| 66 | 100074 | 128 | 100074 |
| 129 | 320 | ||
| 67 | 100090 | 130 | 100090 |
| 131 | 225 | ||
| 68 | 100092 | 132 | 100092 |
| 133 | 424 | ||
| 69 | 100020 | 134 | 100020 |
| 135 | 325 | ||
| 70 | 100096 | 136 | 100096 |
| 137 | 318 | ||
| 71 | 100046 | 138 | 100046 |
| 139 | 238 | ||
| 72 | 100028 | 140 | 100028 |
| 141 | 13 | ||
| 73 | 100072 | 142 | 100072 |
| 143 | 73 | ||
| 74 | 100096 | 144 | 100096 |
| 145 | 262 | ||
| 75 | 100025 | 146 | 100025 |
| 147 | 82 | ||
| 76 | 100001 | 148 | 100001 |
| 149 | 107 | ||
| 77 | 100067 | 150 | 100067 |
| 151 | 410 | ||
| 78 | 100044 | 152 | 100044 |
| 153 | 449 | ||
| 79 | 100063 | 154 | 100063 |
| 155 | 276 | ||
| 80 | 100026 | 156 | 100026 |
| 157 | 392 | ||
| 81 | 100062 | 158 | 100062 |
| 159 | 407 | ||
| 82 | 100091 | 160 | 100091 |
| 161 | 411 | ||
| 83 | 100012 | 162 | 100012 |
| 163 | 400 | ||
| 84 | 100073 | 164 | 100073 |
| 165 | 331 | ||
| 85 | 100051 | 166 | 100051 |
| 167 | 83 | ||
| 86 | 100010 | 168 | 100010 |
| 169 | 385 | ||
| 87 | 100096 | 170 | 100096 |
| 171 | 484 | ||
| 88 | 100043 | 172 | 100043 |
| 173 | 352 | ||
| 89 | 100025 | 174 | 100025 |
| 175 | 207 | ||
| 90 | 100077 | 176 | 100077 |
| 177 | 272 | ||
| 91 | 100089 | 178 | 100089 |
| 179 | 192 | ||
| 92 | 100005 | 180 | 100005 |
| 181 | 291 | ||
| 93 | 100024 | 182 | 100024 |
| 183 | 243 | ||
| 94 | 100091 | 184 | 100091 |
| 185 | 445 | ||
| 95 | 100046 | 186 | 100046 |
| 187 | 162 | ||
| 96 | 100053 | 188 | 100053 |
| 189 | 380 | ||
| 97 | 100058 | 190 | 100058 |
| 191 | 157 | ||
| 98 | 100065 | 192 | 100065 |
| 193 | 464 | ||
| 99 | 100051 | 194 | 100051 |
| 195 | 306 | ||
| 100 | 100056 | 196 | 100056 |
| 197 | 236 | ||
| 101 | 100025 | 198 | 100025 |
| 199 | 198 | ||
| 102 | 100093 | 200 | 100093 |
| 201 | 230 | ||
| 103 | 100088 | 202 | 100088 |
| 203 | 494 | ||
| 104 | 100033 | 204 | 100033 |
| 205 | 70 | ||
| 105 | 100073 | 206 | 100073 |
| 207 | 218 | ||
| 106 | 100048 | 208 | 100048 |
| 209 | 486 | ||
| 107 | 100059 | 210 | 100059 |
| 211 | 77 | ||
| 108 | 100027 | 212 | 100027 |
| 213 | 142 | ||
| 109 | 100045 | 214 | 100045 |
| 215 | 418 | ||
| 110 | 100012 | 216 | 100012 |
| 217 | 68 | ||
| 111 | 100059 | 218 | 100059 |
| 219 | 448 | ||
| 112 | 100084 | 220 | 100084 |
| 221 | 339 | ||
| 113 | 100017 | 222 | 100017 |
| 223 | 39 | ||
| 114 | 100048 | 224 | 100048 |
| 225 | 83 | ||
| 115 | 100004 | 226 | 100004 |
| 227 | 321 | ||
| 116 | 100051 | 228 | 100051 |
| 229 | 441 | ||
| 117 | 100016 | 230 | 100016 |
| 231 | 308 | ||
| 118 | 100088 | 232 | 100088 |
| 233 | 334 | ||
| 119 | 100033 | 234 | 100033 |
| 235 | 476 | ||
| 120 | 100064 | 236 | 100064 |
| 237 | 51 | ||
| 121 | 100060 | 238 | 100060 |
| 239 | 324 | ||
| 122 | 100043 | 240 | 100043 |
| 241 | 149 | ||
| 123 | 100084 | 242 | 100084 |
| 243 | 116 | ||
| 124 | 100026 | 244 | 100026 |
| 245 | 351 | ||
| 125 | 100051 | 246 | 100051 |
| 247 | 396 | ||
| 126 | 100060 | 248 | 100060 |
| 249 | 377 | ||
| 127 | 100069 | 250 | 100069 |
| 251 | 301 | ||
| 128 | 100015 | 252 | 100015 |
| 253 | 319 | ||
| 129 | 100014 | 254 | 100014 |
| 255 | 466 | ||
| 130 | 100038 | 256 | 100038 |
| 257 | 194 | ||
| 131 | 100068 | 258 | 100068 |
| 259 | 41 | ||
| 132 | 100038 | 260 | 100038 |
| 261 | 295 | ||
| 133 | 100097 | 262 | 100097 |
| 263 | 394 | ||
| 134 | 100017 | 264 | 100017 |
| 265 | 34 | ||
| 135 | 100013 | 266 | 100013 |
| 267 | 223 | ||
| 136 | 100053 | 268 | 100053 |
| 269 | 339 | ||
| 137 | 100019 | 270 | 100019 |
| 271 | 67 | ||
| 138 | 100018 | 272 | 100018 |
| 273 | 24 | ||
| 139 | 100081 | 274 | 100081 |
| 275 | 205 | ||
| 140 | 100071 | 276 | 100071 |
| 277 | 440 | ||
| 141 | 100025 | 278 | 100025 |
| 279 | 228 | ||
| 142 | 100014 | 280 | 100014 |
| 281 | 169 | ||
| 143 | 100016 | 282 | 100016 |
| 283 | 121 | ||
| 144 | 100011 | 284 | 100011 |
| 285 | 444 | ||
| 145 | 100069 | 286 | 100069 |
| 287 | 460 | ||
| 146 | 100079 | 288 | 100079 |
| 289 | 139 | ||
| 147 | 100063 | 290 | 100063 |
| 291 | 169 | ||
| 148 | 100070 | 292 | 100070 |
| 293 | 132 | ||
| 149 | 100072 | 294 | 100072 |
| 295 | 119 | ||
| 150 | 100095 | 296 | 100095 |
| 297 | 126 | ||
| 151 | 100042 | 298 | 100042 |
| 299 | 217 | ||
| 152 | 100008 | 300 | 100008 |
| 301 | 272 | ||
| 153 | 100022 | 302 | 100022 |
| 303 | 121 | ||
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 @@ | |||
| 1 | 82 | ||
| 2 | 100000 471 | ||
| 3 | 100001 107 | ||
| 4 | 100002 165 | ||
| 5 | 100004 321 | ||
| 6 | 100005 291 | ||
| 7 | 100006 392 | ||
| 8 | 100007 207 | ||
| 9 | 100008 272 | ||
| 10 | 100009 46 | ||
| 11 | 100010 88 | ||
| 12 | 100011 296 | ||
| 13 | 100012 68 | ||
| 14 | 100013 223 | ||
| 15 | 100014 169 | ||
| 16 | 100015 178 | ||
| 17 | 100016 121 | ||
| 18 | 100017 34 | ||
| 19 | 100018 24 | ||
| 20 | 100019 67 | ||
| 21 | 100020 325 | ||
| 22 | 100021 115 | ||
| 23 | 100022 67 | ||
| 24 | 100024 243 | ||
| 25 | 100025 82 | ||
| 26 | 100026 312 | ||
| 27 | 100027 142 | ||
| 28 | 100028 13 | ||
| 29 | 100029 161 | ||
| 30 | 100030 55 | ||
| 31 | 100031 264 | ||
| 32 | 100033 70 | ||
| 33 | 100036 117 | ||
| 34 | 100037 3 | ||
| 35 | 100038 194 | ||
| 36 | 100039 265 | ||
| 37 | 100041 308 | ||
| 38 | 100042 32 | ||
| 39 | 100043 149 | ||
| 40 | 100044 449 | ||
| 41 | 100045 164 | ||
| 42 | 100046 161 | ||
| 43 | 100047 376 | ||
| 44 | 100048 83 | ||
| 45 | 100049 59 | ||
| 46 | 100051 83 | ||
| 47 | 100052 319 | ||
| 48 | 100053 339 | ||
| 49 | 100056 236 | ||
| 50 | 100058 157 | ||
| 51 | 100059 77 | ||
| 52 | 100060 324 | ||
| 53 | 100062 407 | ||
| 54 | 100063 169 | ||
| 55 | 100064 51 | ||
| 56 | 100065 464 | ||
| 57 | 100066 156 | ||
| 58 | 100067 410 | ||
| 59 | 100068 41 | ||
| 60 | 100069 17 | ||
| 61 | 100070 132 | ||
| 62 | 100071 232 | ||
| 63 | 100072 29 | ||
| 64 | 100073 218 | ||
| 65 | 100074 320 | ||
| 66 | 100075 4 | ||
| 67 | 100076 22 | ||
| 68 | 100077 272 | ||
| 69 | 100079 139 | ||
| 70 | 100081 205 | ||
| 71 | 100084 116 | ||
| 72 | 100086 139 | ||
| 73 | 100087 245 | ||
| 74 | 100088 334 | ||
| 75 | 100089 192 | ||
| 76 | 100090 225 | ||
| 77 | 100091 411 | ||
| 78 | 100092 424 | ||
| 79 | 100093 230 | ||
| 80 | 100095 126 | ||
| 81 | 100096 262 | ||
| 82 | 100097 394 | ||
| 83 | 100099 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 | |||
| 5 | typedef struct { | ||
| 6 | uint64_t n; | ||
| 7 | uint64_t capacity; | ||
| 8 | uint64_t mod; | ||
| 9 | uint64_t *table; | ||
| 10 | } h48map_t; | ||
| 11 | |||
| 12 | typedef struct { | ||
| 13 | uint64_t key; | ||
| 14 | uint64_t val; | ||
| 15 | } kvpair_t; | ||
| 16 | |||
| 17 | void h48map_create(h48map_t *, uint64_t, uint64_t); | ||
| 18 | void h48map_clear(h48map_t *); | ||
| 19 | void h48map_destroy(h48map_t *); | ||
| 20 | uint64_t h48map_lookup(h48map_t *, uint64_t); | ||
| 21 | void h48map_insertmin(h48map_t *, uint64_t, uint64_t); | ||
| 22 | uint64_t h48map_value(h48map_t *, uint64_t); | ||
| 23 | kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); | ||
| 24 | |||
| 25 | char str[STRLENMAX]; | ||
| 26 | |||
| 27 | int 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 | |||
| 36 | uint64_t readl(void) { | ||
| 37 | fgets(str, STRLENMAX, stdin); | ||
| 38 | return atoll(str); | ||
| 39 | } | ||
| 40 | |||
| 41 | void 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 | } | ||
diff --git a/test/112_h48set/00_small.in b/test/112_h48set/00_small.in deleted file mode 100644 index d788d5b..0000000 --- a/test/112_h48set/00_small.in +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | 11 | ||
| 2 | 7 | ||
| 3 | 3 | ||
| 4 | 34 | ||
| 5 | 45 | ||
| 6 | 34 | ||
diff --git a/test/112_h48set/00_small.out b/test/112_h48set/00_small.out deleted file mode 100644 index 29c08e5..0000000 --- a/test/112_h48set/00_small.out +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | 2 | ||
| 2 | 34 | ||
| 3 | 45 | ||
diff --git a/test/112_h48set/01_large.out b/test/112_h48set/01_large.out deleted file mode 100644 index 6632336..0000000 --- a/test/112_h48set/01_large.out +++ /dev/null | |||
| @@ -1,83 +0,0 @@ | |||
| 1 | 82 | ||
| 2 | 100000 | ||
| 3 | 100001 | ||
| 4 | 100002 | ||
| 5 | 100004 | ||
| 6 | 100005 | ||
| 7 | 100006 | ||
| 8 | 100007 | ||
| 9 | 100008 | ||
| 10 | 100009 | ||
| 11 | 100010 | ||
| 12 | 100011 | ||
| 13 | 100012 | ||
| 14 | 100013 | ||
| 15 | 100014 | ||
| 16 | 100015 | ||
| 17 | 100016 | ||
| 18 | 100017 | ||
| 19 | 100018 | ||
| 20 | 100019 | ||
| 21 | 100020 | ||
| 22 | 100021 | ||
| 23 | 100022 | ||
| 24 | 100024 | ||
| 25 | 100025 | ||
| 26 | 100026 | ||
| 27 | 100027 | ||
| 28 | 100028 | ||
| 29 | 100029 | ||
| 30 | 100030 | ||
| 31 | 100031 | ||
| 32 | 100033 | ||
| 33 | 100036 | ||
| 34 | 100037 | ||
| 35 | 100038 | ||
| 36 | 100039 | ||
| 37 | 100041 | ||
| 38 | 100042 | ||
| 39 | 100043 | ||
| 40 | 100044 | ||
| 41 | 100045 | ||
| 42 | 100046 | ||
| 43 | 100047 | ||
| 44 | 100048 | ||
| 45 | 100049 | ||
| 46 | 100051 | ||
| 47 | 100052 | ||
| 48 | 100053 | ||
| 49 | 100056 | ||
| 50 | 100058 | ||
| 51 | 100059 | ||
| 52 | 100060 | ||
| 53 | 100062 | ||
| 54 | 100063 | ||
| 55 | 100064 | ||
| 56 | 100065 | ||
| 57 | 100066 | ||
| 58 | 100067 | ||
| 59 | 100068 | ||
| 60 | 100069 | ||
| 61 | 100070 | ||
| 62 | 100071 | ||
| 63 | 100072 | ||
| 64 | 100073 | ||
| 65 | 100074 | ||
| 66 | 100075 | ||
| 67 | 100076 | ||
| 68 | 100077 | ||
| 69 | 100079 | ||
| 70 | 100081 | ||
| 71 | 100084 | ||
| 72 | 100086 | ||
| 73 | 100087 | ||
| 74 | 100088 | ||
| 75 | 100089 | ||
| 76 | 100090 | ||
| 77 | 100091 | ||
| 78 | 100092 | ||
| 79 | 100093 | ||
| 80 | 100095 | ||
| 81 | 100096 | ||
| 82 | 100097 | ||
| 83 | 100099 | ||
diff --git a/test/112_h48set/h48set_tests.c b/test/112_h48set/h48set_tests.c deleted file mode 100644 index d9310a9..0000000 --- a/test/112_h48set/h48set_tests.c +++ /dev/null | |||
| @@ -1,64 +0,0 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | char str[STRLENMAX]; | ||
| 4 | |||
| 5 | typedef struct { | ||
| 6 | int64_t n; | ||
| 7 | int64_t capacity; | ||
| 8 | int64_t mod; | ||
| 9 | int64_t *table; | ||
| 10 | } h48set_t; | ||
| 11 | |||
| 12 | void h48set_create(h48set_t *, int64_t, int64_t); | ||
| 13 | void h48set_clear(h48set_t *); | ||
| 14 | void h48set_destroy(h48set_t *); | ||
| 15 | int64_t h48set_lookup(h48set_t *, int64_t); | ||
| 16 | void h48set_insert(h48set_t *, int64_t); | ||
| 17 | bool h48set_contains(h48set_t *, int64_t); | ||
| 18 | int64_t h48set_save(h48set_t *, int64_t *); | ||
| 19 | |||
| 20 | int compare(const void *x, const void *y) { | ||
| 21 | int64_t a = *(int64_t *)x; | ||
| 22 | int64_t b = *(int64_t *)y; | ||
| 23 | |||
| 24 | if (a > b) return 1; | ||
| 25 | if (a == b) return 0; | ||
| 26 | return -1; | ||
| 27 | } | ||
| 28 | |||
| 29 | int64_t readl(void) { | ||
| 30 | fgets(str, STRLENMAX, stdin); | ||
| 31 | return atoll(str); | ||
| 32 | } | ||
| 33 | |||
| 34 | void run(void) { | ||
| 35 | h48set_t set; | ||
| 36 | int64_t n, i, k, capacity, mod, *a, *b; | ||
| 37 | |||
| 38 | capacity = readl(); | ||
| 39 | mod = readl(); | ||
| 40 | n = readl(); | ||
| 41 | |||
| 42 | a = malloc(n * sizeof(int64_t)); | ||
| 43 | b = malloc(n * sizeof(int64_t)); | ||
| 44 | for (i = 0; i < n; i++) | ||
| 45 | a[i] = readl(); | ||
| 46 | |||
| 47 | h48set_create(&set, capacity, mod); | ||
| 48 | for (i = 0; i < n; i++) | ||
| 49 | h48set_insert(&set, a[i]); | ||
| 50 | |||
| 51 | k = h48set_save(&set, b); | ||
| 52 | qsort(b, k, sizeof(int64_t), compare); | ||
| 53 | |||
| 54 | printf("%" PRId64 "\n", k); | ||
| 55 | for (i = 0; i < k; i++) | ||
| 56 | printf("%" PRId64 "\n", b[i]); | ||
| 57 | for (i = 0; i < n; i++) | ||
| 58 | if (!h48set_contains(&set, a[i])) | ||
| 59 | printf("Set does not contain %" PRId64 "\n", a[i]); | ||
| 60 | |||
| 61 | h48set_destroy(&set); | ||
| 62 | free(a); | ||
| 63 | free(b); | ||
| 64 | } | ||
