diff options
| -rw-r--r-- | TODO.txt | 13 | ||||
| -rw-r--r-- | src/cube_transform_with_switch.h | 6 | ||||
| -rw-r--r-- | src/solve_h48.h | 73 | ||||
| -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 |
9 files changed, 210 insertions, 45 deletions
| @@ -1,18 +1,19 @@ | |||
| 1 | Bug in esep table generation | 1 | Bug in esep table generation |
| 2 | - add pre-computation of h48 coordinates at distance <=7? | ||
| 3 | - unit tests (but how do I test? just leave it there to check regressions) | ||
| 4 | - Add long-running test for h0k4 (maybe as a tool?) | ||
| 5 | - compute all tables for h<11 | 2 | - compute all tables for h<11 |
| 6 | - compute visited up to a fixed depth (7? 8?) | 3 | x compute visited up to a fixed depth 8 |
| 7 | - compute additional step (if needed) to fill <=base | 4 | - compute additional step (if needed) to fill <=base |
| 8 | - brute-force the last 2 steps (only 18 moves + 18*15 move pairs) | 5 | - brute-force the last 2 steps (only 18 moves + 18*15 move pairs, + sim) |
| 9 | - compare with known h0 results (from long-running test) | 6 | - compare with known h0 results (from long-running test) |
| 10 | - compute table for h=11 | 7 | - compute table for h=11 |
| 11 | - is is worth pre-computing stuff? | ||
| 12 | - can it be unified to the other computation, or is it much better | 8 | - can it be unified to the other computation, or is it much better |
| 13 | to do it ad hoc? | 9 | to do it ad hoc? |
| 10 | - Add long-running test for h0k4 (maybe as a tool?) | ||
| 11 | - tests for other sizes? | ||
| 14 | - optimize | 12 | - optimize |
| 15 | - use cached values for invcoord_esep? check if it is faster | 13 | - use cached values for invcoord_esep? check if it is faster |
| 14 | - Unify and improve performance of finding nasty sim | ||
| 15 | (right now we don't even use selfsim) | ||
| 16 | - parallelize with pthread | ||
| 16 | 17 | ||
| 17 | (OLD: | 18 | (OLD: |
| 18 | - Fails for UFRUFU, try command | 19 | - Fails for UFRUFU, try command |
diff --git a/src/cube_transform_with_switch.h b/src/cube_transform_with_switch.h index 45e1d64..18c1c8c 100644 --- a/src/cube_transform_with_switch.h +++ b/src/cube_transform_with_switch.h | |||
| @@ -118,7 +118,7 @@ transform_edges(cube_t c, uint8_t t) | |||
| 118 | case _trans_BLm: | 118 | case _trans_BLm: |
| 119 | return _trans_edges_mirrored(BLm, c); | 119 | return _trans_edges_mirrored(BLm, c); |
| 120 | default: | 120 | default: |
| 121 | LOG("transform error, unknown transformation\n"); | 121 | LOG("transform error, unknown transformation %" PRIu8 "\n", t); |
| 122 | return zero; | 122 | return zero; |
| 123 | } | 123 | } |
| 124 | } | 124 | } |
| @@ -224,7 +224,7 @@ transform_corners(cube_t c, uint8_t t) | |||
| 224 | case _trans_BLm: | 224 | case _trans_BLm: |
| 225 | return _trans_corners_mirrored(BLm, c); | 225 | return _trans_corners_mirrored(BLm, c); |
| 226 | default: | 226 | default: |
| 227 | LOG("transform error, unknown transformation\n"); | 227 | LOG("transform error, unknown transformation %" PRIu8 "\n", t); |
| 228 | return zero; | 228 | return zero; |
| 229 | } | 229 | } |
| 230 | } | 230 | } |
| @@ -330,7 +330,7 @@ transform(cube_t c, uint8_t t) | |||
| 330 | case _trans_BLm: | 330 | case _trans_BLm: |
| 331 | return _trans_mirrored(BLm, c); | 331 | return _trans_mirrored(BLm, c); |
| 332 | default: | 332 | default: |
| 333 | LOG("transform error, unknown transformation\n"); | 333 | LOG("transform error, unknown transformation %" PRIu8 "\n", t); |
| 334 | return zero; | 334 | return zero; |
| 335 | } | 335 | } |
| 336 | } | 336 | } |
diff --git a/src/solve_h48.h b/src/solve_h48.h index c7cc91c..ad77156 100644 --- a/src/solve_h48.h +++ b/src/solve_h48.h | |||
| @@ -30,7 +30,7 @@ | |||
| 30 | typedef struct { | 30 | typedef struct { |
| 31 | uint64_t n; | 31 | uint64_t n; |
| 32 | uint64_t capacity; | 32 | uint64_t capacity; |
| 33 | uint64_t mod; | 33 | uint64_t randomizer; |
| 34 | uint64_t *table; | 34 | uint64_t *table; |
| 35 | } h48map_t; | 35 | } h48map_t; |
| 36 | 36 | ||
| @@ -112,7 +112,8 @@ _static_inline void set_esep_pval(uint32_t *, int64_t, uint8_t); | |||
| 112 | 112 | ||
| 113 | _static size_t gendata_cocsep(void *, uint64_t *, cube_t *); | 113 | _static size_t gendata_cocsep(void *, uint64_t *, cube_t *); |
| 114 | _static uint32_t gendata_cocsep_dfs(dfsarg_cocsep_t *); | 114 | _static uint32_t gendata_cocsep_dfs(dfsarg_cocsep_t *); |
| 115 | _static int64_t gen_h48map_short(uint8_t, const uint32_t *, h48map_t *); | 115 | _static uint64_t gen_h48short( |
| 116 | uint8_t, const uint32_t *, const cube_t *, const uint64_t *, h48map_t *); | ||
| 116 | _static size_t gendata_h48h0k4(void *, uint8_t); | 117 | _static size_t gendata_h48h0k4(void *, uint8_t); |
| 117 | _static int64_t gendata_h48h0k4_bfs(bfsarg_esep_t *); | 118 | _static int64_t gendata_h48h0k4_bfs(bfsarg_esep_t *); |
| 118 | _static int64_t gendata_h48h0k4_bfs_fromdone(bfsarg_esep_t *); | 119 | _static int64_t gendata_h48h0k4_bfs_fromdone(bfsarg_esep_t *); |
| @@ -123,16 +124,17 @@ _static_inline int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *); | |||
| 123 | _static_inline int8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint32_t *); | 124 | _static_inline int8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint32_t *); |
| 124 | _static_inline bool solve_h48_stop(dfsarg_solveh48_t *); | 125 | _static_inline bool solve_h48_stop(dfsarg_solveh48_t *); |
| 125 | _static int64_t solve_h48_dfs(dfsarg_solveh48_t *); | 126 | _static int64_t solve_h48_dfs(dfsarg_solveh48_t *); |
| 126 | _static int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, uint8_t, const void *, char *); | 127 | _static int64_t solve_h48( |
| 128 | cube_t, int8_t, int8_t, int8_t, uint8_t, const void *, char *); | ||
| 127 | 129 | ||
| 128 | _static int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); | 130 | _static int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); |
| 129 | _static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); | 131 | _static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); |
| 130 | 132 | ||
| 131 | _static void | 133 | _static void |
| 132 | h48map_create(h48map_t *map, uint64_t capacity, uint64_t mod) | 134 | h48map_create(h48map_t *map, uint64_t capacity, uint64_t randomizer) |
| 133 | { | 135 | { |
| 134 | map->capacity = capacity; | 136 | map->capacity = capacity; |
| 135 | map->mod = mod; | 137 | map->randomizer = randomizer; |
| 136 | 138 | ||
| 137 | map->table = malloc(map->capacity * sizeof(int64_t)); | 139 | map->table = malloc(map->capacity * sizeof(int64_t)); |
| 138 | h48map_clear(map); | 140 | h48map_clear(map); |
| @@ -156,7 +158,7 @@ h48map_lookup(h48map_t *map, uint64_t x) | |||
| 156 | { | 158 | { |
| 157 | uint64_t hash, i; | 159 | uint64_t hash, i; |
| 158 | 160 | ||
| 159 | hash = ((x % map->capacity) * map->mod) % map->capacity; | 161 | hash = ((x % map->capacity) * map->randomizer) % map->capacity; |
| 160 | for (i = hash; | 162 | for (i = hash; |
| 161 | map->table[i] != MAP_UNSET && (map->table[i] & MAP_KEYMASK) != x; | 163 | map->table[i] != MAP_UNSET && (map->table[i] & MAP_KEYMASK) != x; |
| 162 | i = (i+1) % map->capacity | 164 | i = (i+1) % map->capacity |
| @@ -384,32 +386,55 @@ gendata_cocsep_dfs(dfsarg_cocsep_t *arg) | |||
| 384 | return cc; | 386 | return cc; |
| 385 | } | 387 | } |
| 386 | 388 | ||
| 387 | _static int64_t | 389 | _static uint64_t |
| 388 | gen_h48map_short(uint8_t n, const uint32_t *cocsepdata, h48map_t *map) | 390 | gen_h48short( |
| 389 | { | 391 | uint8_t n, |
| 390 | /* | 392 | const uint32_t *cocsepdata, |
| 391 | uint8_t i, j, m; | 393 | const cube_t *crep, |
| 392 | int64_t coord; | 394 | const uint64_t *selfsim, |
| 393 | cube_t cube, d; | 395 | h48map_t *map |
| 396 | ) { | ||
| 397 | uint8_t i, m, t; | ||
| 398 | int64_t coord, cc; | ||
| 399 | uint64_t j, oldn, sim; | ||
| 400 | kvpair_t kv; | ||
| 401 | cube_t cube, d, e; | ||
| 394 | 402 | ||
| 395 | cube = solvedcube(); | 403 | cube = solvedcube(); |
| 396 | coord = coord_h48(cube, cocsepdata, 11); | 404 | coord = coord_h48(cube, cocsepdata, 11); |
| 405 | h48map_insertmin(map, coord, 0); | ||
| 406 | oldn = 0; | ||
| 407 | LOG("Short h48: generating depth 0\nfound %" PRIu8 "\n", map->n-oldn); | ||
| 397 | for (i = 0; i < n; i++) { | 408 | for (i = 0; i < n; i++) { |
| 398 | for (j = 0; (coord = h48map_next(map, &j)) != -1; ) { | 409 | LOG("Short h48: generating depth %" PRIu8 "\n", i+1); |
| 399 | cube = invcoord_h48(coord, cocsepdata, 11); | 410 | j = 0; |
| 411 | oldn = map->n; | ||
| 412 | for (kv = h48map_nextkvpair(map, &j); | ||
| 413 | j != map->capacity; | ||
| 414 | kv = h48map_nextkvpair(map, &j) | ||
| 415 | ) { | ||
| 416 | if (kv.val != i) | ||
| 417 | continue; | ||
| 418 | cube = invcoord_h48(kv.key, crep, 11); | ||
| 400 | for (m = 0; m < 18; m++) { | 419 | for (m = 0; m < 18; m++) { |
| 401 | d = move(cube, m); | 420 | d = move(cube, m); |
| 402 | TODO | 421 | coord = coord_h48(d, cocsepdata, 11); |
| 422 | h48map_insertmin(map, coord, i+1); | ||
| 423 | cc = coord / H48_ESIZE(11); | ||
| 424 | sim = selfsim[cc] >> UINT64_C(1); | ||
| 425 | for (t = 1; t < 48 && sim; t++) { | ||
| 426 | /* TODO: optimize by using transform_edges, | ||
| 427 | corner coordinate is kept */ | ||
| 428 | e = transform(d, t); | ||
| 429 | coord = coord_h48(e, cocsepdata, 11); | ||
| 430 | h48map_insertmin(map, coord, i+1); | ||
| 431 | } | ||
| 403 | } | 432 | } |
| 404 | } | 433 | } |
| 434 | LOG("found %" PRIu8 "\n", map->n-oldn); | ||
| 405 | } | 435 | } |
| 406 | */ | ||
| 407 | } | ||
| 408 | 436 | ||
| 409 | _static int64_t | 437 | return map->n; |
| 410 | gen_h48set_short_dfs(dfsarg_genh48set_t *arg) | ||
| 411 | { | ||
| 412 | /* TODO */ | ||
| 413 | } | 438 | } |
| 414 | 439 | ||
| 415 | /* | 440 | /* |
| @@ -511,7 +536,7 @@ gendata_h48h0k4_bfs_fromdone(bfsarg_esep_t *arg) | |||
| 511 | cc += x != arg->depth; | 536 | cc += x != arg->depth; |
| 512 | cocsep_coord = j / H48_ESIZE(0); | 537 | cocsep_coord = j / H48_ESIZE(0); |
| 513 | sim = arg->selfsim[cocsep_coord] >> UINT64_C(1); | 538 | sim = arg->selfsim[cocsep_coord] >> UINT64_C(1); |
| 514 | for (t = 1; t < 48 && sim; t++, sim >>= UINT64_C(1)) { | 539 | for (t = 1; t < 48 && sim; t++) { |
| 515 | /* TODO: use only selfsim */ | 540 | /* TODO: use only selfsim */ |
| 516 | transd = transform(moved, t); | 541 | transd = transform(moved, t); |
| 517 | k = coord_h48(transd, arg->cocsepdata, 0); | 542 | k = coord_h48(transd, arg->cocsepdata, 0); |
| @@ -553,7 +578,7 @@ neighbor_found: | |||
| 553 | cc++; | 578 | cc++; |
| 554 | cocsep_coord = i / H48_ESIZE(0); | 579 | cocsep_coord = i / H48_ESIZE(0); |
| 555 | sim = arg->selfsim[cocsep_coord] >> 1; | 580 | sim = arg->selfsim[cocsep_coord] >> 1; |
| 556 | for (t = 1; t < 48 && sim; t++, sim >>= 1) { | 581 | for (t = 1; t < 48 && sim; t++) { |
| 557 | /* TODO: use only selfsim */ | 582 | /* TODO: use only selfsim */ |
| 558 | transd = transform(cube, t); | 583 | transd = transform(cube, t); |
| 559 | j = coord_h48(transd, arg->cocsepdata, 0); | 584 | j = coord_h48(transd, arg->cocsepdata, 0); |
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 | } | ||
