aboutsummaryrefslogtreecommitdiff
path: root/test/112_h48map/h48map_tests.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-07-18 19:39:44 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-07-18 19:39:44 +0200
commite20e4f550ae373414d9bc106b1615a5c5896c9c4 (patch)
treea7501b4940655cf64e560ad768732a554f1b6f09 /test/112_h48map/h48map_tests.c
parent7946c8efc2e2a44a8e78e1263c1691ce9f412a09 (diff)
downloadnissy-core-e20e4f550ae373414d9bc106b1615a5c5896c9c4.tar.gz
nissy-core-e20e4f550ae373414d9bc106b1615a5c5896c9c4.zip
Added pre-computation of short h48 positions
Diffstat (limited to '')
-rw-r--r--test/112_h48map/h48map_tests.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/test/112_h48map/h48map_tests.c b/test/112_h48map/h48map_tests.c
index ce8f657..d70bc3a 100644
--- a/test/112_h48map/h48map_tests.c
+++ b/test/112_h48map/h48map_tests.c
@@ -1,11 +1,12 @@
1#include "../test.h" 1#include "../test.h"
2 2
3#define MAP_KEYSHIFT UINT64_C(40) 3#define MAP_KEYSHIFT UINT64_C(40)
4#define MAXPOS 1000
4 5
5typedef struct { 6typedef struct {
6 uint64_t n; 7 uint64_t n;
7 uint64_t capacity; 8 uint64_t capacity;
8 uint64_t mod; 9 uint64_t randomizer;
9 uint64_t *table; 10 uint64_t *table;
10} h48map_t; 11} h48map_t;
11 12
@@ -15,9 +16,7 @@ typedef struct {
15} kvpair_t; 16} kvpair_t;
16 17
17void h48map_create(h48map_t *, uint64_t, uint64_t); 18void h48map_create(h48map_t *, uint64_t, uint64_t);
18void h48map_clear(h48map_t *);
19void h48map_destroy(h48map_t *); 19void h48map_destroy(h48map_t *);
20uint64_t h48map_lookup(h48map_t *, uint64_t);
21void h48map_insertmin(h48map_t *, uint64_t, uint64_t); 20void h48map_insertmin(h48map_t *, uint64_t, uint64_t);
22uint64_t h48map_value(h48map_t *, uint64_t); 21uint64_t h48map_value(h48map_t *, uint64_t);
23kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); 22kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *);
@@ -40,28 +39,26 @@ uint64_t readl(void) {
40 39
41void run(void) { 40void run(void) {
42 h48map_t map; 41 h48map_t map;
43 uint64_t n, i, j, capacity, mod, x, y, v; 42 uint64_t n, i, j, capacity, randomizer, x, y, v;
44 kvpair_t kv, *a, *b; 43 kvpair_t kv, a[MAXPOS], b[MAXPOS];
45 44
46 capacity = readl(); 45 capacity = readl();
47 mod = readl(); 46 randomizer = readl();
48 n = readl(); 47 n = readl();
49 48
50 a = malloc(n * sizeof(kvpair_t));
51 b = malloc(n * sizeof(kvpair_t));
52 for (i = 0; i < n; i++) { 49 for (i = 0; i < n; i++) {
53 x = readl(); 50 x = readl();
54 y = readl(); 51 y = readl();
55 a[i] = (kvpair_t) { .key = x, .val = y }; 52 a[i] = (kvpair_t) { .key = x, .val = y };
56 } 53 }
57 54
58 h48map_create(&map, capacity, mod); 55 h48map_create(&map, capacity, randomizer);
59 for (i = 0; i < n; i++) 56 for (i = 0; i < n; i++)
60 h48map_insertmin(&map, a[i].key, a[i].val); 57 h48map_insertmin(&map, a[i].key, a[i].val);
61 58
62 i = 0; 59 i = 0;
63 for (kv = h48map_nextkvpair(&map, &i), j = 0; 60 for (kv = h48map_nextkvpair(&map, &i), j = 0;
64 i != map.capacity; 61 i != map.capacity && j < MAXPOS;
65 kv = h48map_nextkvpair(&map, &i) 62 kv = h48map_nextkvpair(&map, &i)
66 ) { 63 ) {
67 b[j++] = kv; 64 b[j++] = kv;
@@ -83,6 +80,4 @@ void run(void) {
83 } 80 }
84 81
85 h48map_destroy(&map); 82 h48map_destroy(&map);
86 free(a);
87 free(b);
88} 83}

Generated with cgit - Back to sebastiano.tronto.net