aboutsummaryrefslogtreecommitdiff
path: root/test/112_h48map/h48map_tests.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-07-20 10:05:51 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-07-20 10:05:51 +0200
commit5727f06c5694a4831881322876e3ba4d8ce3b743 (patch)
tree8ec57e5862b05464b54aad3aad6f3d37653066a6 /test/112_h48map/h48map_tests.c
parente20e4f550ae373414d9bc106b1615a5c5896c9c4 (diff)
downloadnissy-core-5727f06c5694a4831881322876e3ba4d8ce3b743.tar.gz
nissy-core-5727f06c5694a4831881322876e3ba4d8ce3b743.zip
Finally fixed selfsim logic
Diffstat (limited to 'test/112_h48map/h48map_tests.c')
-rw-r--r--test/112_h48map/h48map_tests.c83
1 files changed, 0 insertions, 83 deletions
diff --git a/test/112_h48map/h48map_tests.c b/test/112_h48map/h48map_tests.c
deleted file mode 100644
index d70bc3a..0000000
--- a/test/112_h48map/h48map_tests.c
+++ /dev/null
@@ -1,83 +0,0 @@
1#include "../test.h"
2
3#define MAP_KEYSHIFT UINT64_C(40)
4#define MAXPOS 1000
5
6typedef struct {
7 uint64_t n;
8 uint64_t capacity;
9 uint64_t randomizer;
10 uint64_t *table;
11} h48map_t;
12
13typedef struct {
14 uint64_t key;
15 uint64_t val;
16} kvpair_t;
17
18void h48map_create(h48map_t *, uint64_t, uint64_t);
19void h48map_destroy(h48map_t *);
20void h48map_insertmin(h48map_t *, uint64_t, uint64_t);
21uint64_t h48map_value(h48map_t *, uint64_t);
22kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *);
23
24char str[STRLENMAX];
25
26int compare(const void *x, const void *y) {
27 uint64_t a = ((kvpair_t *)x)->key;
28 uint64_t b = ((kvpair_t *)y)->key;
29
30 if (a > b) return 1;
31 if (a == b) return 0;
32 return -1;
33}
34
35uint64_t readl(void) {
36 fgets(str, STRLENMAX, stdin);
37 return atoll(str);
38}
39
40void run(void) {
41 h48map_t map;
42 uint64_t n, i, j, capacity, randomizer, x, y, v;
43 kvpair_t kv, a[MAXPOS], b[MAXPOS];
44
45 capacity = readl();
46 randomizer = readl();
47 n = readl();
48
49 for (i = 0; i < n; i++) {
50 x = readl();
51 y = readl();
52 a[i] = (kvpair_t) { .key = x, .val = y };
53 }
54
55 h48map_create(&map, capacity, randomizer);
56 for (i = 0; i < n; i++)
57 h48map_insertmin(&map, a[i].key, a[i].val);
58
59 i = 0;
60 for (kv = h48map_nextkvpair(&map, &i), j = 0;
61 i != map.capacity && j < MAXPOS;
62 kv = h48map_nextkvpair(&map, &i)
63 ) {
64 b[j++] = kv;
65 }
66 qsort(b, j, sizeof(kvpair_t), compare);
67
68 printf("%" PRIu64 "\n", map.n);
69 for (i = 0; i < j; i++)
70 printf("%" PRIu64 " %" PRIu64 "\n", b[i].key, b[i].val);
71 if (map.n != j)
72 printf("Wrong number of elements: map->n = %" PRIu64 ", "
73 "but scan returns %" PRIu64 "\n", map.n, j);
74 for (i = 0; i < n; i++) {
75 v = h48map_value(&map, a[i].key);
76 if (v > a[i].val)
77 printf("Value for key %" PRId64 " is larger than "
78 "expected (%" PRIu64 " > %" PRIu64 ")\n",
79 a[i].key, v, a[i].val);
80 }
81
82 h48map_destroy(&map);
83}

Generated with cgit - Back to sebastiano.tronto.net