diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-05-18 08:48:13 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-05-18 08:48:13 +0200 |
| commit | 8b94d135429a9f3253cc7f25a1453b412065c4a0 (patch) | |
| tree | 4a31d6def5421e95fb98505a2bc2653c18fca330 /src/solvers/coord | |
| parent | 30b43f08955158d4f2066f4b50fe8d1241b3177b (diff) | |
| download | nissy-core-8b94d135429a9f3253cc7f25a1453b412065c4a0.tar.gz nissy-core-8b94d135429a9f3253cc7f25a1453b412065c4a0.zip | |
Refactor solver dispatch and checkdata
Diffstat (limited to 'src/solvers/coord')
| -rw-r--r-- | src/solvers/coord/gendata.h | 35 | ||||
| -rw-r--r-- | src/solvers/coord/solve.h | 35 | ||||
| -rw-r--r-- | src/solvers/coord/utils.h | 12 |
3 files changed, 34 insertions, 48 deletions
diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h index 7a974f8..1b65f49 100644 --- a/src/solvers/coord/gendata.h +++ b/src/solvers/coord/gendata.h | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | STATIC size_t gendata_coord(const coord_t [static 1], unsigned char *); | 1 | STATIC size_t gendata_coord(const coord_t [static 1], unsigned char *); |
| 2 | STATIC int64_t gendata_coord_dispatch(const char *, unsigned char *); | 2 | STATIC long long gendata_coord_dispatch(const char *, unsigned long long, |
| 3 | unsigned char *); | ||
| 3 | STATIC tableinfo_t genptable_coord( | 4 | STATIC tableinfo_t genptable_coord( |
| 4 | const coord_t [static 1], const unsigned char *, unsigned char *); | 5 | const coord_t [static 1], const unsigned char *, unsigned char *); |
| 5 | STATIC bool switch_to_fromnew(uint64_t, uint64_t, uint64_t); | 6 | STATIC bool switch_to_fromnew(uint64_t, uint64_t, uint64_t); |
| @@ -7,15 +8,17 @@ STATIC uint64_t genptable_coord_fillneighbors(const coord_t [static 1], | |||
| 7 | const unsigned char *, uint64_t, uint8_t, unsigned char *); | 8 | const unsigned char *, uint64_t, uint8_t, unsigned char *); |
| 8 | STATIC uint64_t genptable_coord_fillfromnew(const coord_t [static 1], | 9 | STATIC uint64_t genptable_coord_fillfromnew(const coord_t [static 1], |
| 9 | const unsigned char *, uint64_t, uint8_t, unsigned char *); | 10 | const unsigned char *, uint64_t, uint8_t, unsigned char *); |
| 10 | STATIC void getdistribution_coord(const unsigned char *, const char *, | ||
| 11 | uint64_t [static INFO_DISTRIBUTION_LEN]); | ||
| 12 | STATIC uint8_t get_coord_pval( | 11 | STATIC uint8_t get_coord_pval( |
| 13 | const coord_t [static 1], const unsigned char *, uint64_t); | 12 | const coord_t [static 1], const unsigned char *, uint64_t); |
| 14 | STATIC void set_coord_pval( | 13 | STATIC void set_coord_pval( |
| 15 | const coord_t [static 1], unsigned char *, uint64_t, uint8_t); | 14 | const coord_t [static 1], unsigned char *, uint64_t, uint8_t); |
| 16 | 15 | ||
| 17 | STATIC int64_t | 16 | STATIC long long |
| 18 | gendata_coord_dispatch(const char *coordstr, unsigned char *buf) | 17 | gendata_coord_dispatch( |
| 18 | const char *coordstr, | ||
| 19 | unsigned long long bufsize, | ||
| 20 | unsigned char *buf | ||
| 21 | ) | ||
| 19 | { | 22 | { |
| 20 | coord_t *coord; | 23 | coord_t *coord; |
| 21 | 24 | ||
| @@ -249,28 +252,6 @@ genptable_coord_fillfromnew( | |||
| 249 | return tot; | 252 | return tot; |
| 250 | } | 253 | } |
| 251 | 254 | ||
| 252 | STATIC void | ||
| 253 | getdistribution_coord( | ||
| 254 | const unsigned char *table, | ||
| 255 | const char *coord, | ||
| 256 | uint64_t distr[static INFO_DISTRIBUTION_LEN] | ||
| 257 | ) | ||
| 258 | { | ||
| 259 | uint8_t v; | ||
| 260 | uint64_t i; | ||
| 261 | coord_t *c; | ||
| 262 | |||
| 263 | memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); | ||
| 264 | |||
| 265 | if((c = parse_coord(strlen(coord), coord)) == NULL) | ||
| 266 | return; | ||
| 267 | |||
| 268 | for (i = 0; i < c->max; i++) { | ||
| 269 | v = get_coord_pval(c, table, i); | ||
| 270 | distr[v]++; | ||
| 271 | } | ||
| 272 | } | ||
| 273 | |||
| 274 | STATIC uint8_t | 255 | STATIC uint8_t |
| 275 | get_coord_pval( | 256 | get_coord_pval( |
| 276 | const coord_t coord[static 1], | 257 | const coord_t coord[static 1], |
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index 8eb3e9d..df0f6ff 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h | |||
| @@ -13,11 +13,13 @@ typedef struct { | |||
| 13 | } dfsarg_solve_coord_t; | 13 | } dfsarg_solve_coord_t; |
| 14 | 14 | ||
| 15 | STATIC int64_t solve_coord(oriented_cube_t, coord_t [static 1], uint8_t, | 15 | STATIC int64_t solve_coord(oriented_cube_t, coord_t [static 1], uint8_t, |
| 16 | uint8_t, uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, | 16 | uint8_t, uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t n, |
| 17 | const unsigned char *, size_t n, char [n], int (*)(void *), void *); | 17 | const unsigned char [n], size_t m, char [m], int (*)(void *), void *); |
| 18 | STATIC int64_t solve_coord_dispatch(oriented_cube_t, const char *, uint8_t, | 18 | STATIC long long solve_coord_dispatch(oriented_cube_t, const char *, unsigned, |
| 19 | uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, | 19 | unsigned, unsigned, unsigned, unsigned, unsigned, unsigned long long n, |
| 20 | const unsigned char *, size_t n, char [n], int (*)(void *), void *); | 20 | const unsigned char [n], unsigned m, char [m], |
| 21 | long long [static NISSY_SIZE_SOLVE_STATS], | ||
| 22 | int (*)(void *), void *); | ||
| 21 | STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]); | 23 | STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]); |
| 22 | STATIC bool solve_coord_dfs_stop(const dfsarg_solve_coord_t [static 1]); | 24 | STATIC bool solve_coord_dfs_stop(const dfsarg_solve_coord_t [static 1]); |
| 23 | STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]); | 25 | STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]); |
| @@ -198,20 +200,21 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) | |||
| 198 | return ret; | 200 | return ret; |
| 199 | } | 201 | } |
| 200 | 202 | ||
| 201 | STATIC int64_t | 203 | STATIC long long |
| 202 | solve_coord_dispatch( | 204 | solve_coord_dispatch( |
| 203 | oriented_cube_t oc, | 205 | oriented_cube_t oc, |
| 204 | const char *coord_and_axis, | 206 | const char *coord_and_axis, |
| 205 | uint8_t nissflag, | 207 | unsigned nissflag, |
| 206 | uint8_t minmoves, | 208 | unsigned minmoves, |
| 207 | uint8_t maxmoves, | 209 | unsigned maxmoves, |
| 208 | uint64_t maxsolutions, | 210 | unsigned maxsolutions, |
| 209 | uint8_t optimal, | 211 | unsigned optimal, |
| 210 | uint8_t threads, | 212 | unsigned threads, |
| 211 | uint64_t data_size, | 213 | unsigned long long data_size, |
| 212 | const unsigned char *data, | 214 | const unsigned char data[data_size], |
| 213 | size_t solutions_size, | 215 | unsigned solutions_size, |
| 214 | char sols[solutions_size], | 216 | char sols[solutions_size], |
| 217 | long long stats[static NISSY_SIZE_SOLVE_STATS], | ||
| 215 | int (*poll_status)(void *), | 218 | int (*poll_status)(void *), |
| 216 | void *poll_status_data | 219 | void *poll_status_data |
| 217 | ) | 220 | ) |
| @@ -250,7 +253,7 @@ solve_coord( | |||
| 250 | uint8_t optimal, | 253 | uint8_t optimal, |
| 251 | uint8_t threads, | 254 | uint8_t threads, |
| 252 | uint64_t data_size, | 255 | uint64_t data_size, |
| 253 | const unsigned char *data, | 256 | const unsigned char data[data_size], |
| 254 | size_t solutions_size, | 257 | size_t solutions_size, |
| 255 | char sols[solutions_size], | 258 | char sols[solutions_size], |
| 256 | int (*poll_status)(void *), | 259 | int (*poll_status)(void *), |
diff --git a/src/solvers/coord/utils.h b/src/solvers/coord/utils.h index ef3f817..aa4d74c 100644 --- a/src/solvers/coord/utils.h +++ b/src/solvers/coord/utils.h | |||
| @@ -2,7 +2,7 @@ STATIC coord_t *parse_coord(size_t n, const char [n]); | |||
| 2 | STATIC uint8_t parse_axis(size_t n, const char [n]); | 2 | STATIC uint8_t parse_axis(size_t n, const char [n]); |
| 3 | STATIC void parse_coord_and_axis( | 3 | STATIC void parse_coord_and_axis( |
| 4 | size_t n, const char [n], coord_t **, uint8_t *); | 4 | size_t n, const char [n], coord_t **, uint8_t *); |
| 5 | STATIC int64_t dataid_coord(const char *, char [static NISSY_SIZE_DATAID]); | 5 | STATIC long long dataid_coord(const char *, char [static NISSY_SIZE_DATAID]); |
| 6 | 6 | ||
| 7 | STATIC coord_t * | 7 | STATIC coord_t * |
| 8 | parse_coord(size_t n, const char coord[n]) | 8 | parse_coord(size_t n, const char coord[n]) |
| @@ -38,20 +38,22 @@ parse_coord_and_axis( | |||
| 38 | uint8_t *axis | 38 | uint8_t *axis |
| 39 | ) | 39 | ) |
| 40 | { | 40 | { |
| 41 | const char *s; | ||
| 41 | size_t i; | 42 | size_t i; |
| 42 | 43 | ||
| 44 | s = str + 6; | ||
| 43 | for (i = 0; i < n; i++) | 45 | for (i = 0; i < n; i++) |
| 44 | if (str[i] == '_') | 46 | if (s[i] == '_') |
| 45 | break; | 47 | break; |
| 46 | 48 | ||
| 47 | if (coord != NULL) | 49 | if (coord != NULL) |
| 48 | *coord = parse_coord(i, str); | 50 | *coord = parse_coord(i, s); |
| 49 | 51 | ||
| 50 | if (axis != NULL) | 52 | if (axis != NULL) |
| 51 | *axis = i == n ? UINT8_ERROR : parse_axis(n-i-1, str+i+1); | 53 | *axis = i == n ? UINT8_ERROR : parse_axis(n-i-1, s+i+1); |
| 52 | } | 54 | } |
| 53 | 55 | ||
| 54 | STATIC int64_t | 56 | STATIC long long |
| 55 | dataid_coord(const char *ca, char dataid[static NISSY_SIZE_DATAID]) | 57 | dataid_coord(const char *ca, char dataid[static NISSY_SIZE_DATAID]) |
| 56 | { | 58 | { |
| 57 | coord_t *c; | 59 | coord_t *c; |
