aboutsummaryrefslogtreecommitdiff
path: root/test/112_h48set/h48set_tests.c
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_h48set/h48set_tests.c
parent3d060c348fdfff074a9b902d56f539664789d831 (diff)
downloadnissy-core-7946c8efc2e2a44a8e78e1263c1691ce9f412a09.tar.gz
nissy-core-7946c8efc2e2a44a8e78e1263c1691ce9f412a09.zip
Converted set to map
Diffstat (limited to 'test/112_h48set/h48set_tests.c')
-rw-r--r--test/112_h48set/h48set_tests.c64
1 files changed, 0 insertions, 64 deletions
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
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);
18int64_t h48set_save(h48set_t *, int64_t *);
19
20int 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
29int64_t readl(void) {
30 fgets(str, STRLENMAX, stdin);
31 return atoll(str);
32}
33
34void 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}

Generated with cgit - Back to sebastiano.tronto.net