diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-18 19:39:44 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-18 19:39:44 +0200 |
| commit | e20e4f550ae373414d9bc106b1615a5c5896c9c4 (patch) | |
| tree | a7501b4940655cf64e560ad768732a554f1b6f09 /test | |
| parent | 7946c8efc2e2a44a8e78e1263c1691ce9f412a09 (diff) | |
| download | nissy-core-e20e4f550ae373414d9bc106b1615a5c5896c9c4.tar.gz nissy-core-e20e4f550ae373414d9bc106b1615a5c5896c9c4.zip | |
Added pre-computation of short h48 positions
Diffstat (limited to 'test')
| -rw-r--r-- | test/112_h48map/h48map_tests.c | 19 | ||||
| -rw-r--r-- | test/113_gen_h48short/00_depth_1.in | 28 | ||||
| -rw-r--r-- | test/113_gen_h48short/00_depth_1.out | 3 | ||||
| -rw-r--r-- | test/113_gen_h48short/01_depth_3.in | 3 | ||||
| -rw-r--r-- | test/113_gen_h48short/01_depth_3.out | 40 | ||||
| -rw-r--r-- | test/113_gen_h48short/gen_h48short.c | 70 |
6 files changed, 151 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 | ||
| 5 | typedef struct { | 6 | typedef 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 | ||
| 17 | void h48map_create(h48map_t *, uint64_t, uint64_t); | 18 | void h48map_create(h48map_t *, uint64_t, uint64_t); |
| 18 | void h48map_clear(h48map_t *); | ||
| 19 | void h48map_destroy(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); | 20 | void h48map_insertmin(h48map_t *, uint64_t, uint64_t); |
| 22 | uint64_t h48map_value(h48map_t *, uint64_t); | 21 | uint64_t h48map_value(h48map_t *, uint64_t); |
| 23 | kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); | 22 | kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); |
| @@ -40,28 +39,26 @@ uint64_t readl(void) { | |||
| 40 | 39 | ||
| 41 | void run(void) { | 40 | void 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 | } |
diff --git a/test/113_gen_h48short/00_depth_1.in b/test/113_gen_h48short/00_depth_1.in new file mode 100644 index 0000000..c86f15b --- /dev/null +++ b/test/113_gen_h48short/00_depth_1.in | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | 73 | ||
| 2 | 157 | ||
| 3 | 1 | ||
| 4 | |||
| 5 | For longer test: | ||
| 6 | |||
| 7 | 20000003 | ||
| 8 | 20000023 | ||
| 9 | 8 | ||
| 10 | |||
| 11 | Short h48: generating depth 0 | ||
| 12 | found 1 | ||
| 13 | Short h48: generating depth 1 | ||
| 14 | found 1 | ||
| 15 | Short h48: generating depth 2 | ||
| 16 | found 4 | ||
| 17 | Short h48: generating depth 3 | ||
| 18 | found 34 | ||
| 19 | Short h48: generating depth 4 | ||
| 20 | found 333 | ||
| 21 | Short h48: generating depth 5 | ||
| 22 | found 3815 | ||
| 23 | Short h48: generating depth 6 | ||
| 24 | found 45382 | ||
| 25 | Short h48: generating depth 7 | ||
| 26 | found 548562 | ||
| 27 | Short h48: generating depth 8 | ||
| 28 | found 6839723 | ||
diff --git a/test/113_gen_h48short/00_depth_1.out b/test/113_gen_h48short/00_depth_1.out new file mode 100644 index 0000000..b0dba31 --- /dev/null +++ b/test/113_gen_h48short/00_depth_1.out | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | 2 | ||
| 2 | 0 0 | ||
| 3 | 71075840 1 | ||
diff --git a/test/113_gen_h48short/01_depth_3.in b/test/113_gen_h48short/01_depth_3.in new file mode 100644 index 0000000..920e70a --- /dev/null +++ b/test/113_gen_h48short/01_depth_3.in | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | 73 | ||
| 2 | 157 | ||
| 3 | 3 | ||
diff --git a/test/113_gen_h48short/01_depth_3.out b/test/113_gen_h48short/01_depth_3.out new file mode 100644 index 0000000..dbce376 --- /dev/null +++ b/test/113_gen_h48short/01_depth_3.out | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | 40 | ||
| 2 | 0 0 | ||
| 3 | 70981632 3 | ||
| 4 | 71075840 1 | ||
| 5 | 71086080 3 | ||
| 6 | 142067712 2 | ||
| 7 | 218789888 3 | ||
| 8 | 218884096 2 | ||
| 9 | 283879424 2 | ||
| 10 | 283899904 3 | ||
| 11 | 283953152 3 | ||
| 12 | 283973632 2 | ||
| 13 | 360548808 3 | ||
| 14 | 360835072 3 | ||
| 15 | 473668032 3 | ||
| 16 | 473956352 3 | ||
| 17 | 499869696 3 | ||
| 18 | 500011008 3 | ||
| 19 | 598679552 3 | ||
| 20 | 599109185 3 | ||
| 21 | 662171648 3 | ||
| 22 | 662601226 3 | ||
| 23 | 724818316 3 | ||
| 24 | 725106688 3 | ||
| 25 | 790513664 3 | ||
| 26 | 790607872 3 | ||
| 27 | 904991108 3 | ||
| 28 | 926726144 3 | ||
| 29 | 928729088 3 | ||
| 30 | 1009662340 3 | ||
| 31 | 1088755203 3 | ||
| 32 | 1171758595 3 | ||
| 33 | 1206452224 3 | ||
| 34 | 1206480896 3 | ||
| 35 | 1277360128 3 | ||
| 36 | 1277454336 3 | ||
| 37 | 1403695492 3 | ||
| 38 | 1403697540 3 | ||
| 39 | 1403736452 3 | ||
| 40 | 1403738500 3 | ||
diff --git a/test/113_gen_h48short/gen_h48short.c b/test/113_gen_h48short/gen_h48short.c new file mode 100644 index 0000000..399ef1e --- /dev/null +++ b/test/113_gen_h48short/gen_h48short.c | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | #define COCSEP_CLASSES 3393 | ||
| 4 | #define MAXPOS 200 | ||
| 5 | |||
| 6 | typedef struct { | ||
| 7 | uint64_t n; | ||
| 8 | uint64_t capacity; | ||
| 9 | uint64_t randomizer; | ||
| 10 | uint64_t *table; | ||
| 11 | } h48map_t; | ||
| 12 | |||
| 13 | typedef struct { | ||
| 14 | uint64_t key; | ||
| 15 | uint64_t val; | ||
| 16 | } kvpair_t; | ||
| 17 | |||
| 18 | void h48map_create(h48map_t *, uint64_t, uint64_t); | ||
| 19 | void h48map_destroy(h48map_t *); | ||
| 20 | kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); | ||
| 21 | size_t gendata_cocsep(void *, uint64_t *, cube_t *); | ||
| 22 | uint64_t gen_h48short( | ||
| 23 | uint8_t, const uint32_t *, const cube_t *, const uint64_t *, h48map_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 | uint32_t cocsepdata[300000]; | ||
| 43 | h48map_t map; | ||
| 44 | uint64_t n, i, j, capacity, randomizer, selfsim[COCSEP_CLASSES]; | ||
| 45 | kvpair_t kv, b[MAXPOS]; | ||
| 46 | cube_t crep[COCSEP_CLASSES]; | ||
| 47 | |||
| 48 | capacity = readl(); | ||
| 49 | randomizer = readl(); | ||
| 50 | n = readl(); | ||
| 51 | |||
| 52 | h48map_create(&map, capacity, randomizer); | ||
| 53 | gendata_cocsep(cocsepdata, selfsim, crep); | ||
| 54 | gen_h48short(n, cocsepdata, crep, selfsim, &map); | ||
| 55 | |||
| 56 | i = 0; | ||
| 57 | for (kv = h48map_nextkvpair(&map, &i), j = 0; | ||
| 58 | i != map.capacity && j < MAXPOS; | ||
| 59 | kv = h48map_nextkvpair(&map, &i) | ||
| 60 | ) { | ||
| 61 | b[j++] = kv; | ||
| 62 | } | ||
| 63 | qsort(b, j, sizeof(kvpair_t), compare); | ||
| 64 | |||
| 65 | printf("%" PRIu64 "\n", map.n); | ||
| 66 | for (i = 0; i < j; i++) | ||
| 67 | printf("%" PRIu64 " %" PRIu64 "\n", b[i].key, b[i].val); | ||
| 68 | |||
| 69 | h48map_destroy(&map); | ||
| 70 | } | ||
