aboutsummaryrefslogtreecommitdiff
path: root/src/solve_h48.h
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 /src/solve_h48.h
parent7946c8efc2e2a44a8e78e1263c1691ce9f412a09 (diff)
downloadnissy-core-e20e4f550ae373414d9bc106b1615a5c5896c9c4.tar.gz
nissy-core-e20e4f550ae373414d9bc106b1615a5c5896c9c4.zip
Added pre-computation of short h48 positions
Diffstat (limited to 'src/solve_h48.h')
-rw-r--r--src/solve_h48.h73
1 files changed, 49 insertions, 24 deletions
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 @@
30typedef struct { 30typedef 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
132h48map_create(h48map_t *map, uint64_t capacity, uint64_t mod) 134h48map_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
388gen_h48map_short(uint8_t n, const uint32_t *cocsepdata, h48map_t *map) 390gen_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);
402TODO 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;
410gen_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);

Generated with cgit - Back to sebastiano.tronto.net