diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-14 16:18:29 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-14 16:18:29 +0100 |
| commit | 1e1fd628207034b0412c50e289f146d34c5baf71 (patch) | |
| tree | f21715cf39ef5fcc0a9197b214702fb7d16a1c58 | |
| parent | bfb7b1ab9d2c85a256c42c006060ffe7c2652638 (diff) | |
| download | nissy-core-1e1fd628207034b0412c50e289f146d34c5baf71.tar.gz nissy-core-1e1fd628207034b0412c50e289f146d34c5baf71.zip | |
Replaced datasize with solverinfo
| -rw-r--r-- | TODO_COORDINATES | 2 | ||||
| -rw-r--r-- | python/nissy_module.c | 26 | ||||
| -rw-r--r-- | shell/shell.c | 55 | ||||
| -rw-r--r-- | src/nissy.c | 37 | ||||
| -rw-r--r-- | src/nissy.h | 14 | ||||
| -rw-r--r-- | src/solvers/coord/common.h | 18 | ||||
| -rw-r--r-- | src/solvers/coord/types_macros.h | 2 | ||||
| -rw-r--r-- | tools/000_gendata/gendata.c | 6 | ||||
| -rw-r--r-- | tools/100_checkdata/checkdata.c | 6 | ||||
| -rw-r--r-- | tools/300_solve_small/solve_small.c | 4 | ||||
| -rw-r--r-- | tools/301_solve_file/solve_file.c | 4 | ||||
| -rw-r--r-- | tools/302_solve_multisol/solve_multisol.c | 4 | ||||
| -rw-r--r-- | tools/400_solvetest/solve_test.c | 4 | ||||
| -rw-r--r-- | tools/tool.h | 26 |
14 files changed, 140 insertions, 68 deletions
diff --git a/TODO_COORDINATES b/TODO_COORDINATES index 78ed704..5aa0544 100644 --- a/TODO_COORDINATES +++ b/TODO_COORDINATES | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | - coord solver | 1 | - coord solver |
| 2 | - add checkdata for coord | ||
| 2 | - return to fully qualified solver name | 3 | - return to fully qualified solver name |
| 3 | x undo chnages to API | 4 | x undo chnages to API |
| 4 | - add a parameter to gendata to get a shortname (filename) for the table | 5 | - add a parameter to gendata to get a shortname (filename) for the table |
| @@ -30,3 +31,4 @@ | |||
| 30 | 31 | ||
| 31 | - refactor common parts of coord and h48 solvers | 32 | - refactor common parts of coord and h48 solvers |
| 32 | - move parse_h48 to h48 module? | 33 | - move parse_h48 to h48 module? |
| 34 | then maybe do like for coordinate and exclude the "h48" part | ||
diff --git a/python/nissy_module.c b/python/nissy_module.c index 29facc4..db63dbb 100644 --- a/python/nissy_module.c +++ b/python/nissy_module.c | |||
| @@ -219,27 +219,33 @@ getcube(PyObject *self, PyObject *args) | |||
| 219 | return string_result(err, result); | 219 | return string_result(err, result); |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | PyDoc_STRVAR(datasize_doc, | 222 | PyDoc_STRVAR(solverinfo_doc, |
| 223 | "datasize(solver)\n" | 223 | "solverinfo(solver)\n" |
| 224 | "--\n\n" | 224 | "--\n\n" |
| 225 | "Returns the size of the data (pruning table) for the given solver\n" | 225 | "Returns the size and the short name of the data for the given solver\n" |
| 226 | "\n" | 226 | "\n" |
| 227 | "Parameters:\n" | 227 | "Parameters:\n" |
| 228 | " - solver: the name of the solver\n" | 228 | " - solver: the name of the solver\n" |
| 229 | "\n" | 229 | "\n" |
| 230 | "Returns: the size of the data for the solver, in bytes\n" | 230 | "Returns: a pair containing the size and the short name " |
| 231 | "of the data for the solver, in bytes\n" | ||
| 231 | ); | 232 | ); |
| 232 | static PyObject * | 233 | static PyObject * |
| 233 | datasize(PyObject *self, PyObject *args) | 234 | solverinfo(PyObject *self, PyObject *args) |
| 234 | { | 235 | { |
| 235 | long long result; | 236 | long long result; |
| 236 | const char *solver; | 237 | const char *solver; |
| 238 | char buf[NISSY_DATAID_SIZE]; | ||
| 239 | PyObject *py_result, *py_buf; | ||
| 237 | 240 | ||
| 238 | if (!PyArg_ParseTuple(args, "s", &solver)) | 241 | if (!PyArg_ParseTuple(args, "s", &solver)) |
| 239 | return NULL; | 242 | return NULL; |
| 240 | 243 | ||
| 241 | result = nissy_datasize(solver); | 244 | result = nissy_solverinfo(solver, buf); |
| 242 | return long_result(result); | 245 | |
| 246 | py_result = PyLong_FromLong(result); | ||
| 247 | py_buf = PyUnicode_FromString(buf); | ||
| 248 | return PyTuple_Pack(2, py_result, py_buf); | ||
| 243 | } | 249 | } |
| 244 | 250 | ||
| 245 | PyDoc_STRVAR(gendata_doc, | 251 | PyDoc_STRVAR(gendata_doc, |
| @@ -257,12 +263,12 @@ gendata(PyObject *self, PyObject *args) | |||
| 257 | { | 263 | { |
| 258 | long long size, err; | 264 | long long size, err; |
| 259 | const char *solver; | 265 | const char *solver; |
| 260 | char *buf; | 266 | char *buf, dataid[NISSY_DATAID_SIZE]; |
| 261 | 267 | ||
| 262 | if (!PyArg_ParseTuple(args, "s", &solver)) | 268 | if (!PyArg_ParseTuple(args, "s", &solver)) |
| 263 | return NULL; | 269 | return NULL; |
| 264 | 270 | ||
| 265 | size = nissy_datasize(solver); | 271 | size = nissy_solverinfo(solver, dataid); |
| 266 | if (!check_error(size)) | 272 | if (!check_error(size)) |
| 267 | return NULL; | 273 | return NULL; |
| 268 | 274 | ||
| @@ -394,7 +400,7 @@ static PyMethodDef nissy_methods[] = { | |||
| 394 | { "applytrans", applytrans, METH_VARARGS, applytrans_doc }, | 400 | { "applytrans", applytrans, METH_VARARGS, applytrans_doc }, |
| 395 | { "convert", convert, METH_VARARGS, convert_doc }, | 401 | { "convert", convert, METH_VARARGS, convert_doc }, |
| 396 | { "getcube", getcube, METH_VARARGS, getcube_doc }, | 402 | { "getcube", getcube, METH_VARARGS, getcube_doc }, |
| 397 | { "datasize", datasize, METH_VARARGS, datasize_doc }, | 403 | { "solverinfo", solverinfo, METH_VARARGS, solverinfo_doc }, |
| 398 | { "gendata", gendata, METH_VARARGS, gendata_doc }, | 404 | { "gendata", gendata, METH_VARARGS, gendata_doc }, |
| 399 | { "checkdata", checkdata, METH_VARARGS, checkdata_doc }, | 405 | { "checkdata", checkdata, METH_VARARGS, checkdata_doc }, |
| 400 | { "solve", solve, METH_VARARGS, solve_doc }, | 406 | { "solve", solve, METH_VARARGS, solve_doc }, |
diff --git a/shell/shell.c b/shell/shell.c index 2a1a8cd..0387856 100644 --- a/shell/shell.c +++ b/shell/shell.c | |||
| @@ -65,7 +65,7 @@ static int64_t applytrans_exec(args_t *); | |||
| 65 | static int64_t frommoves_exec(args_t *); | 65 | static int64_t frommoves_exec(args_t *); |
| 66 | static int64_t convert_exec(args_t *); | 66 | static int64_t convert_exec(args_t *); |
| 67 | static int64_t randomcube_exec(args_t *); | 67 | static int64_t randomcube_exec(args_t *); |
| 68 | static int64_t datasize_exec(args_t *); | 68 | static int64_t solverinfo_exec(args_t *); |
| 69 | static int64_t gendata_exec(args_t *); | 69 | static int64_t gendata_exec(args_t *); |
| 70 | static int64_t solve_exec(args_t *); | 70 | static int64_t solve_exec(args_t *); |
| 71 | static int64_t solve_scramble_exec(args_t *); | 71 | static int64_t solve_scramble_exec(args_t *); |
| @@ -180,11 +180,11 @@ struct { | |||
| 180 | randomcube_exec | 180 | randomcube_exec |
| 181 | ), | 181 | ), |
| 182 | COMMAND( | 182 | COMMAND( |
| 183 | "datasize", | 183 | "solverinfo", |
| 184 | "datasize " FLAG_SOLVER " SOLVER", | 184 | "solverinfo " FLAG_SOLVER " SOLVER", |
| 185 | "Return the size in bytes of the data table used by " | 185 | "Return the size in bytes and the id of the data table " |
| 186 | "SOLVER when called with the given OPTIONS.", | 186 | "used by SOLVER when called with the given OPTIONS.", |
| 187 | datasize_exec | 187 | solverinfo_exec |
| 188 | ), | 188 | ), |
| 189 | COMMAND( | 189 | COMMAND( |
| 190 | "gendata", | 190 | "gendata", |
| @@ -340,14 +340,15 @@ randomcube_exec(args_t *args) | |||
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | static int64_t | 342 | static int64_t |
| 343 | datasize_exec(args_t *args) | 343 | solverinfo_exec(args_t *args) |
| 344 | { | 344 | { |
| 345 | int64_t ret; | 345 | int64_t ret; |
| 346 | char buf[NISSY_DATAID_SIZE]; | ||
| 346 | 347 | ||
| 347 | ret = nissy_datasize(args->str_solver); | 348 | ret = nissy_solverinfo(args->str_solver, buf); |
| 348 | if (ret < 0) | 349 | if (ret < 0) |
| 349 | fprintf(stderr, "Unknown error (make sure solver is valid)\n"); | 350 | fprintf(stderr, "Unknown error (make sure solver is valid)\n"); |
| 350 | printf("%" PRId64 "\n", ret); | 351 | printf("%" PRId64 "\n%s\n", ret, buf); |
| 351 | 352 | ||
| 352 | return ret; | 353 | return ret; |
| 353 | } | 354 | } |
| @@ -357,14 +358,22 @@ gendata_exec(args_t *args) | |||
| 357 | { | 358 | { |
| 358 | int i; | 359 | int i; |
| 359 | FILE *file; | 360 | FILE *file; |
| 360 | char *buf, path[MAX_PATH_LENGTH]; | 361 | char *buf, path[MAX_PATH_LENGTH], dataid[NISSY_DATAID_SIZE]; |
| 361 | int64_t ret, size; | 362 | int64_t ret, size; |
| 362 | size_t written; | 363 | size_t written; |
| 363 | 364 | ||
| 365 | size = nissy_solverinfo(args->str_solver, dataid); | ||
| 366 | |||
| 367 | if (size < 0) { | ||
| 368 | fprintf(stderr, "gendata: unknown solver %s\n", | ||
| 369 | args->str_solver); | ||
| 370 | return -3; | ||
| 371 | } | ||
| 372 | |||
| 364 | /* TODO: should give warning if overwriting existing file */ | 373 | /* TODO: should give warning if overwriting existing file */ |
| 365 | for (i = 0; tablepaths[i] != NULL; i++) { | 374 | for (i = 0; tablepaths[i] != NULL; i++) { |
| 366 | strcpy(path, tablepaths[i]); | 375 | strcpy(path, tablepaths[i]); |
| 367 | strcat(path, args->str_solver); | 376 | strcat(path, dataid); |
| 368 | file = fopen(path, "wb"); | 377 | file = fopen(path, "wb"); |
| 369 | if (file != NULL) | 378 | if (file != NULL) |
| 370 | break; | 379 | break; |
| @@ -376,16 +385,6 @@ gendata_exec(args_t *args) | |||
| 376 | return -2; | 385 | return -2; |
| 377 | } | 386 | } |
| 378 | 387 | ||
| 379 | size = nissy_datasize(args->str_solver); | ||
| 380 | |||
| 381 | if (size < 0) { | ||
| 382 | fprintf(stderr, | ||
| 383 | "Unknown error in retrieving data size" | ||
| 384 | "(make sure solver is valid)\n"); | ||
| 385 | fclose(file); | ||
| 386 | return -3; | ||
| 387 | } | ||
| 388 | |||
| 389 | buf = malloc(size); | 388 | buf = malloc(size); |
| 390 | 389 | ||
| 391 | ret = nissy_gendata(args->str_solver, size, buf); | 390 | ret = nissy_gendata(args->str_solver, size, buf); |
| @@ -427,15 +426,24 @@ solve_exec(args_t *args) | |||
| 427 | uint8_t nissflag; | 426 | uint8_t nissflag; |
| 428 | FILE *file; | 427 | FILE *file; |
| 429 | char *buf, solutions[SOLUTIONS_BUFFER_SIZE], path[MAX_PATH_LENGTH]; | 428 | char *buf, solutions[SOLUTIONS_BUFFER_SIZE], path[MAX_PATH_LENGTH]; |
| 429 | char dataid[NISSY_DATAID_SIZE]; | ||
| 430 | long long stats[NISSY_SIZE_SOLVE_STATS]; | 430 | long long stats[NISSY_SIZE_SOLVE_STATS]; |
| 431 | int64_t ret, gendata_ret, size; | 431 | int64_t ret, gendata_ret, size; |
| 432 | size_t read; | 432 | size_t read; |
| 433 | 433 | ||
| 434 | nissflag = NISSY_NISSFLAG_NORMAL; /* TODO: parse str_nisstype */ | 434 | nissflag = NISSY_NISSFLAG_NORMAL; /* TODO: parse str_nisstype */ |
| 435 | 435 | ||
| 436 | size = nissy_solverinfo(args->str_solver, dataid); | ||
| 437 | |||
| 438 | if (size < 0) { | ||
| 439 | fprintf(stderr, "solve: unknown solver %s\n", | ||
| 440 | args->str_solver); | ||
| 441 | return size; | ||
| 442 | } | ||
| 443 | |||
| 436 | for (i = 0; tablepaths[i] != NULL; i++) { | 444 | for (i = 0; tablepaths[i] != NULL; i++) { |
| 437 | strcpy(path, tablepaths[i]); | 445 | strcpy(path, tablepaths[i]); |
| 438 | strcat(path, args->str_solver); | 446 | strcat(path, dataid); |
| 439 | file = fopen(path, "rb"); | 447 | file = fopen(path, "rb"); |
| 440 | if (file != NULL) | 448 | if (file != NULL) |
| 441 | break; | 449 | break; |
| @@ -454,7 +462,7 @@ solve_exec(args_t *args) | |||
| 454 | if (file == NULL) { | 462 | if (file == NULL) { |
| 455 | for (i = 0; tablepaths[i] != NULL; i++) { | 463 | for (i = 0; tablepaths[i] != NULL; i++) { |
| 456 | strcpy(path, tablepaths[i]); | 464 | strcpy(path, tablepaths[i]); |
| 457 | strcat(path, args->str_solver); | 465 | strcat(path, dataid); |
| 458 | file = fopen(path, "rb"); | 466 | file = fopen(path, "rb"); |
| 459 | if (file != NULL) | 467 | if (file != NULL) |
| 460 | break; | 468 | break; |
| @@ -467,7 +475,6 @@ solve_exec(args_t *args) | |||
| 467 | return -1; | 475 | return -1; |
| 468 | } | 476 | } |
| 469 | 477 | ||
| 470 | size = nissy_datasize(args->str_solver); | ||
| 471 | buf = malloc(size); | 478 | buf = malloc(size); |
| 472 | read = fread(buf, size, 1, file); | 479 | read = fread(buf, size, 1, file); |
| 473 | fclose(file); | 480 | fclose(file); |
diff --git a/src/nissy.c b/src/nissy.c index eb483a0..2766b12 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -19,6 +19,7 @@ STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], | |||
| 19 | const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); | 19 | const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); |
| 20 | STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]); | 20 | STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]); |
| 21 | STATIC size_t my_strnlen(const char *, size_t); | 21 | STATIC size_t my_strnlen(const char *, size_t); |
| 22 | STATIC long long nissy_dataid(const char *, char [static NISSY_DATAID_SIZE]); | ||
| 22 | STATIC long long nissy_gendata_unsafe( | 23 | STATIC long long nissy_gendata_unsafe( |
| 23 | const char *, unsigned long long, char *); | 24 | const char *, unsigned long long, char *); |
| 24 | 25 | ||
| @@ -412,11 +413,37 @@ nissy_datainfo( | |||
| 412 | return NISSY_OK; | 413 | return NISSY_OK; |
| 413 | } | 414 | } |
| 414 | 415 | ||
| 416 | STATIC long long | ||
| 417 | nissy_dataid(const char *solver, char dataid[static NISSY_DATAID_SIZE]) | ||
| 418 | { | ||
| 419 | if (!strncmp(solver, "h48", 3)) { | ||
| 420 | uint8_t h, k; | ||
| 421 | long long err; | ||
| 422 | if ((err = parse_h48_solver(solver, &h, &k)) != NISSY_OK) | ||
| 423 | return err; | ||
| 424 | /* TODO: also check that h and k are admissible */ | ||
| 425 | else strcpy(dataid, solver); | ||
| 426 | return err; | ||
| 427 | /* TODO: do this when moved parser */ | ||
| 428 | /* return dataid_h48(solver, dataid); */ | ||
| 429 | } else if (!strncmp(solver, "coord_", 6)) { | ||
| 430 | return dataid_coord(solver+6, dataid); | ||
| 431 | } else { | ||
| 432 | LOG("gendata: unknown solver %s\n", solver); | ||
| 433 | return NISSY_ERROR_INVALID_SOLVER; | ||
| 434 | } | ||
| 435 | } | ||
| 436 | |||
| 415 | long long | 437 | long long |
| 416 | nissy_datasize( | 438 | nissy_solverinfo( |
| 417 | const char *solver | 439 | const char *solver, |
| 440 | char dataid[static NISSY_DATAID_SIZE] | ||
| 418 | ) | 441 | ) |
| 419 | { | 442 | { |
| 443 | long long err; | ||
| 444 | if ((err = nissy_dataid(solver, dataid)) != NISSY_OK) | ||
| 445 | return err; | ||
| 446 | |||
| 420 | /* gendata() handles a NULL *data as a "dryrun" request */ | 447 | /* gendata() handles a NULL *data as a "dryrun" request */ |
| 421 | return nissy_gendata_unsafe(solver, 0, NULL); | 448 | return nissy_gendata_unsafe(solver, 0, NULL); |
| 422 | } | 449 | } |
| @@ -447,7 +474,7 @@ nissy_gendata_unsafe( | |||
| 447 | } | 474 | } |
| 448 | 475 | ||
| 449 | if ((size_t)data % 8 != 0) { | 476 | if ((size_t)data % 8 != 0) { |
| 450 | LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); | 477 | LOG("nissy_gendata: buffere is not 8-byte aligned\n"); |
| 451 | return NISSY_ERROR_DATA; | 478 | return NISSY_ERROR_DATA; |
| 452 | } | 479 | } |
| 453 | 480 | ||
| @@ -478,7 +505,7 @@ nissy_checkdata( | |||
| 478 | int64_t err; | 505 | int64_t err; |
| 479 | 506 | ||
| 480 | if ((size_t)data % 8 != 0) { | 507 | if ((size_t)data % 8 != 0) { |
| 481 | LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); | 508 | LOG("nissy_checkdata: buffere is not 8-byte aligned\n"); |
| 482 | return NISSY_ERROR_DATA; | 509 | return NISSY_ERROR_DATA; |
| 483 | } | 510 | } |
| 484 | 511 | ||
| @@ -560,7 +587,7 @@ nissy_solve( | |||
| 560 | } | 587 | } |
| 561 | 588 | ||
| 562 | if ((size_t)data % 8 != 0) { | 589 | if ((size_t)data % 8 != 0) { |
| 563 | LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); | 590 | LOG("nissy_solve: buffere is not 8-byte aligned\n"); |
| 564 | return NISSY_ERROR_DATA; | 591 | return NISSY_ERROR_DATA; |
| 565 | } | 592 | } |
| 566 | 593 | ||
diff --git a/src/nissy.h b/src/nissy.h index 6c5a3e6..23bcb8b 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -25,6 +25,7 @@ for example 'rotation UF' or 'mirrored BL'. | |||
| 25 | #define NISSY_SIZE_H48 88U | 25 | #define NISSY_SIZE_H48 88U |
| 26 | #define NISSY_SIZE_TRANSFORMATION 12U | 26 | #define NISSY_SIZE_TRANSFORMATION 12U |
| 27 | #define NISSY_SIZE_SOLVE_STATS 10U | 27 | #define NISSY_SIZE_SOLVE_STATS 10U |
| 28 | #define NISSY_DATAID_SIZE 255U | ||
| 28 | 29 | ||
| 29 | /* Flags for NISS options */ | 30 | /* Flags for NISS options */ |
| 30 | #define NISSY_NISSFLAG_NORMAL 1U | 31 | #define NISSY_NISSFLAG_NORMAL 1U |
| @@ -191,11 +192,15 @@ nissy_getcube( | |||
| 191 | ); | 192 | ); |
| 192 | 193 | ||
| 193 | /* | 194 | /* |
| 194 | Compute the size of the data generated by nissy_gendata, when called with | 195 | Compute the size of the data generated by nissy_gendata when called for |
| 195 | the same parameters, or -1 in case of error. | 196 | the given solver, and other useful information. |
| 196 | 197 | ||
| 197 | Parameters: | 198 | Parameters: |
| 198 | solver - The name of the solver. | 199 | solver - The name of the solver. |
| 200 | dataid - An identifier for the data computed for the solver. Different | ||
| 201 | solver may use equivalent data. This identifier can be used | ||
| 202 | e.g. as a filename or database key to save and retrieve the | ||
| 203 | correct data for each solver, without duplication. | ||
| 199 | 204 | ||
| 200 | Return values: | 205 | Return values: |
| 201 | NISSY_ERROR_INVALID_SOLVER - The given solver is not known. | 206 | NISSY_ERROR_INVALID_SOLVER - The given solver is not known. |
| @@ -204,8 +209,9 @@ Return values: | |||
| 204 | Any value >= 0 - The size of the data, in bytes. | 209 | Any value >= 0 - The size of the data, in bytes. |
| 205 | */ | 210 | */ |
| 206 | long long | 211 | long long |
| 207 | nissy_datasize( | 212 | nissy_solverinfo( |
| 208 | const char *solver | 213 | const char *solver, |
| 214 | char dataid[static NISSY_DATAID_SIZE] | ||
| 209 | ); | 215 | ); |
| 210 | 216 | ||
| 211 | /* | 217 | /* |
diff --git a/src/solvers/coord/common.h b/src/solvers/coord/common.h index f21a903..d570b6d 100644 --- a/src/solvers/coord/common.h +++ b/src/solvers/coord/common.h | |||
| @@ -7,6 +7,7 @@ STATIC void append_coord_name(const coord_t *, char *); | |||
| 7 | STATIC coord_t *parse_coord(const char *, int); | 7 | STATIC coord_t *parse_coord(const char *, int); |
| 8 | STATIC uint8_t parse_axis(const char *, int); | 8 | STATIC uint8_t parse_axis(const char *, int); |
| 9 | STATIC void parse_coord_and_axis(const char *, int, coord_t **, uint8_t *); | 9 | STATIC void parse_coord_and_axis(const char *, int, coord_t **, uint8_t *); |
| 10 | STATIC int64_t dataid_coord(const char *, char [static NISSY_DATAID_SIZE]); | ||
| 10 | 11 | ||
| 11 | STATIC void | 12 | STATIC void |
| 12 | append_coord_name(const coord_t *coord, char *str) | 13 | append_coord_name(const coord_t *coord, char *str) |
| @@ -61,3 +62,20 @@ parse_coord_and_axis(const char *str, int n, coord_t **coord, uint8_t *axis) | |||
| 61 | if (axis != NULL) | 62 | if (axis != NULL) |
| 62 | *axis = i == n ? UINT8_ERROR : parse_axis(str+i+1, n-i-1); | 63 | *axis = i == n ? UINT8_ERROR : parse_axis(str+i+1, n-i-1); |
| 63 | } | 64 | } |
| 65 | |||
| 66 | STATIC int64_t | ||
| 67 | dataid_coord(const char *ca, char dataid[static NISSY_DATAID_SIZE]) | ||
| 68 | { | ||
| 69 | coord_t *c; | ||
| 70 | |||
| 71 | parse_coord_and_axis(ca, strlen(ca), &c, NULL); | ||
| 72 | |||
| 73 | if (c == NULL) { | ||
| 74 | LOG("dataid_coord: cannot parse coordinate from '%s'\n", ca); | ||
| 75 | return NISSY_ERROR_INVALID_SOLVER; | ||
| 76 | } | ||
| 77 | |||
| 78 | strcpy(dataid, c->name); | ||
| 79 | |||
| 80 | return NISSY_OK; | ||
| 81 | } | ||
diff --git a/src/solvers/coord/types_macros.h b/src/solvers/coord/types_macros.h index 594f594..84085ad 100644 --- a/src/solvers/coord/types_macros.h +++ b/src/solvers/coord/types_macros.h | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | #define COORD_MASK(i) (UINT8_C(0xF) << COORD_SHIFT(i)) | 3 | #define COORD_MASK(i) (UINT8_C(0xF) << COORD_SHIFT(i)) |
| 4 | 4 | ||
| 5 | typedef struct { | 5 | typedef struct { |
| 6 | char name[255]; | 6 | const char name[255]; |
| 7 | uint64_t (*coord)(cube_t, const void *); | 7 | uint64_t (*coord)(cube_t, const void *); |
| 8 | cube_t (*cube)(uint64_t, const void *); | 8 | cube_t (*cube)(uint64_t, const void *); |
| 9 | size_t (*gendata)(void *); | 9 | size_t (*gendata)(void *); |
diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c index 213852f..51c2f47 100644 --- a/tools/000_gendata/gendata.c +++ b/tools/000_gendata/gendata.c | |||
| @@ -8,9 +8,9 @@ static void | |||
| 8 | run(void) { | 8 | run(void) { |
| 9 | int64_t size; | 9 | int64_t size; |
| 10 | bool consistent, expected; | 10 | bool consistent, expected; |
| 11 | char *buf, filename[1024]; | 11 | char *buf, filename[1024], dataid[NISSY_DATAID_SIZE]; |
| 12 | 12 | ||
| 13 | size = generatetable(solver, &buf); | 13 | size = generatetable(solver, &buf, dataid); |
| 14 | switch (size) { | 14 | switch (size) { |
| 15 | case -1: | 15 | case -1: |
| 16 | return; | 16 | return; |
| @@ -23,7 +23,7 @@ run(void) { | |||
| 23 | if (consistent && expected) { | 23 | if (consistent && expected) { |
| 24 | printf("\n"); | 24 | printf("\n"); |
| 25 | printf("Generated %" PRId64 " bytes.\n", size); | 25 | printf("Generated %" PRId64 " bytes.\n", size); |
| 26 | sprintf(filename, "tables/%s", solver); | 26 | sprintf(filename, "tables/%s", dataid); |
| 27 | writetable(buf, size, filename); | 27 | writetable(buf, size, filename); |
| 28 | } | 28 | } |
| 29 | if (!consistent) | 29 | if (!consistent) |
diff --git a/tools/100_checkdata/checkdata.c b/tools/100_checkdata/checkdata.c index fe94427..8bc308c 100644 --- a/tools/100_checkdata/checkdata.c +++ b/tools/100_checkdata/checkdata.c | |||
| @@ -6,13 +6,13 @@ char *solver, *filename; | |||
| 6 | static void | 6 | static void |
| 7 | run(void) { | 7 | run(void) { |
| 8 | long long int size, result; | 8 | long long int size, result; |
| 9 | char *buf; | 9 | char *buf, dataid[NISSY_DATAID_SIZE]; |
| 10 | FILE *f; | 10 | FILE *f; |
| 11 | 11 | ||
| 12 | size = nissy_datasize(solver); | 12 | size = nissy_solverinfo(solver, dataid); |
| 13 | 13 | ||
| 14 | if (size <= 0) { | 14 | if (size <= 0) { |
| 15 | printf("Error in datasize\n"); | 15 | printf("Error in solverinfo\n"); |
| 16 | return; | 16 | return; |
| 17 | } | 17 | } |
| 18 | 18 | ||
diff --git a/tools/300_solve_small/solve_small.c b/tools/300_solve_small/solve_small.c index 073de89..6a1f7b5 100644 --- a/tools/300_solve_small/solve_small.c +++ b/tools/300_solve_small/solve_small.c | |||
| @@ -46,7 +46,7 @@ void run(void) { | |||
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | int main(int argc, char **argv) { | 48 | int main(int argc, char **argv) { |
| 49 | char filename[255]; | 49 | char filename[255], dataid[NISSY_DATAID_SIZE]; |
| 50 | 50 | ||
| 51 | if (argc < 2) { | 51 | if (argc < 2) { |
| 52 | printf("Error: not enough arguments. " | 52 | printf("Error: not enough arguments. " |
| @@ -63,7 +63,7 @@ int main(int argc, char **argv) { | |||
| 63 | if (getdata(solver, &buf, filename) != 0) | 63 | if (getdata(solver, &buf, filename) != 0) |
| 64 | return 1; | 64 | return 1; |
| 65 | 65 | ||
| 66 | size = nissy_datasize(solver); | 66 | size = nissy_solverinfo(solver, dataid); |
| 67 | 67 | ||
| 68 | timerun(run); | 68 | timerun(run); |
| 69 | 69 | ||
diff --git a/tools/301_solve_file/solve_file.c b/tools/301_solve_file/solve_file.c index fe41bb7..cefc608 100644 --- a/tools/301_solve_file/solve_file.c +++ b/tools/301_solve_file/solve_file.c | |||
| @@ -33,7 +33,7 @@ void run(void) { | |||
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | int main(int argc, char **argv) { | 35 | int main(int argc, char **argv) { |
| 36 | char filename[255], *scrfilename; | 36 | char filename[255], dataid[NISSY_DATAID_SIZE], *scrfilename; |
| 37 | FILE *scrfile; | 37 | FILE *scrfile; |
| 38 | 38 | ||
| 39 | if (argc < 3) { | 39 | if (argc < 3) { |
| @@ -52,7 +52,7 @@ int main(int argc, char **argv) { | |||
| 52 | if (getdata(solver, &buf, filename) != 0) | 52 | if (getdata(solver, &buf, filename) != 0) |
| 53 | return 1; | 53 | return 1; |
| 54 | 54 | ||
| 55 | size = nissy_datasize(solver); | 55 | size = nissy_solverinfo(solver, dataid); |
| 56 | 56 | ||
| 57 | if ((scrfile = fopen(scrfilename, "r")) == NULL) { | 57 | if ((scrfile = fopen(scrfilename, "r")) == NULL) { |
| 58 | printf("Error: could not read given file '%s'.\n", | 58 | printf("Error: could not read given file '%s'.\n", |
diff --git a/tools/302_solve_multisol/solve_multisol.c b/tools/302_solve_multisol/solve_multisol.c index a03c2a0..c6ab685 100644 --- a/tools/302_solve_multisol/solve_multisol.c +++ b/tools/302_solve_multisol/solve_multisol.c | |||
| @@ -39,7 +39,7 @@ void run(void) { | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | int main(int argc, char **argv) { | 41 | int main(int argc, char **argv) { |
| 42 | char filename[255]; | 42 | char filename[255], dataid[NISSY_DATAID_SIZE]; |
| 43 | 43 | ||
| 44 | if (argc < 3) { | 44 | if (argc < 3) { |
| 45 | printf("Error: not enough arguments. " | 45 | printf("Error: not enough arguments. " |
| @@ -57,7 +57,7 @@ int main(int argc, char **argv) { | |||
| 57 | if (getdata(solver, &buf, filename) != 0) | 57 | if (getdata(solver, &buf, filename) != 0) |
| 58 | return 1; | 58 | return 1; |
| 59 | 59 | ||
| 60 | size = nissy_datasize(solver); | 60 | size = nissy_solverinfo(solver, dataid); |
| 61 | 61 | ||
| 62 | timerun(run); | 62 | timerun(run); |
| 63 | 63 | ||
diff --git a/tools/400_solvetest/solve_test.c b/tools/400_solvetest/solve_test.c index 9b6c094..a98be26 100644 --- a/tools/400_solvetest/solve_test.c +++ b/tools/400_solvetest/solve_test.c | |||
| @@ -94,7 +94,7 @@ void run(void) { | |||
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | int main(int argc, char **argv) { | 96 | int main(int argc, char **argv) { |
| 97 | char filename[255]; | 97 | char filename[255], dataid[NISSY_DATAID_SIZE]; |
| 98 | 98 | ||
| 99 | if (argc < 2) { | 99 | if (argc < 2) { |
| 100 | printf("Error: not enough arguments. " | 100 | printf("Error: not enough arguments. " |
| @@ -110,7 +110,7 @@ int main(int argc, char **argv) { | |||
| 110 | if (getdata(solver, &buf, filename) != 0) | 110 | if (getdata(solver, &buf, filename) != 0) |
| 111 | return 1; | 111 | return 1; |
| 112 | 112 | ||
| 113 | size = nissy_datasize(solver); | 113 | size = nissy_solverinfo(solver, dataid); |
| 114 | 114 | ||
| 115 | timerun(run); | 115 | timerun(run); |
| 116 | 116 | ||
diff --git a/tools/tool.h b/tools/tool.h index 3488f34..b65f33a 100644 --- a/tools/tool.h +++ b/tools/tool.h | |||
| @@ -13,7 +13,8 @@ static void log_stderr(const char *, ...); | |||
| 13 | static void log_stdout(const char *, ...); | 13 | static void log_stdout(const char *, ...); |
| 14 | static double timerun(void (*)(void)); | 14 | static double timerun(void (*)(void)); |
| 15 | static void writetable(const char *, int64_t, const char *); | 15 | static void writetable(const char *, int64_t, const char *); |
| 16 | static long long int generatetable(const char *, char **); | 16 | static long long int generatetable(const char *, char **, |
| 17 | char [static NISSY_DATAID_SIZE]); | ||
| 17 | static long long int derivetable( | 18 | static long long int derivetable( |
| 18 | const char *, const char *, const char *, char **); | 19 | const char *, const char *, const char *, char **); |
| 19 | static int getdata(const char *, char **, const char *); | 20 | static int getdata(const char *, char **, const char *); |
| @@ -86,11 +87,15 @@ writetable(const char *buf, int64_t size, const char *filename) | |||
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | static long long int | 89 | static long long int |
| 89 | generatetable(const char *solver, char **buf) | 90 | generatetable( |
| 91 | const char *solver, | ||
| 92 | char **buf, | ||
| 93 | char dataid[static NISSY_DATAID_SIZE] | ||
| 94 | ) | ||
| 90 | { | 95 | { |
| 91 | long long int size, gensize; | 96 | long long int size, gensize; |
| 92 | 97 | ||
| 93 | size = nissy_datasize(solver); | 98 | size = nissy_solverinfo(solver, dataid); |
| 94 | if (size < 0) { | 99 | if (size < 0) { |
| 95 | printf("Error getting table size.\n"); | 100 | printf("Error getting table size.\n"); |
| 96 | return -1; | 101 | return -1; |
| @@ -120,7 +125,7 @@ derivetable( | |||
| 120 | { | 125 | { |
| 121 | uint8_t h, k; | 126 | uint8_t h, k; |
| 122 | long long int size, gensize; | 127 | long long int size, gensize; |
| 123 | char *fulltable; | 128 | char *fulltable, dataid[NISSY_DATAID_SIZE]; |
| 124 | 129 | ||
| 125 | if (getdata(solver_large, &fulltable, filename_large) != 0) { | 130 | if (getdata(solver_large, &fulltable, filename_large) != 0) { |
| 126 | printf("Error reading full table.\n"); | 131 | printf("Error reading full table.\n"); |
| @@ -128,7 +133,7 @@ derivetable( | |||
| 128 | goto derivetable_error_nofree; | 133 | goto derivetable_error_nofree; |
| 129 | } | 134 | } |
| 130 | 135 | ||
| 131 | size = nissy_datasize(solver_small); | 136 | size = nissy_solverinfo(solver_small, dataid); |
| 132 | if (size == -1) { | 137 | if (size == -1) { |
| 133 | printf("Error getting table size.\n"); | 138 | printf("Error getting table size.\n"); |
| 134 | gensize = -2; | 139 | gensize = -2; |
| @@ -164,10 +169,11 @@ getdata( | |||
| 164 | ) { | 169 | ) { |
| 165 | long long int size, sizeread; | 170 | long long int size, sizeread; |
| 166 | FILE *f; | 171 | FILE *f; |
| 172 | char dataid[NISSY_DATAID_SIZE]; | ||
| 167 | 173 | ||
| 168 | if ((f = fopen(filename, "rb")) == NULL) { | 174 | if ((f = fopen(filename, "rb")) == NULL) { |
| 169 | printf("Table file not found, generating it.\n"); | 175 | printf("Table file not found, generating it.\n"); |
| 170 | size = generatetable(solver, buf); | 176 | size = generatetable(solver, buf, dataid); |
| 171 | switch (size) { | 177 | switch (size) { |
| 172 | case -1: | 178 | case -1: |
| 173 | goto getdata_error_nofree; | 179 | goto getdata_error_nofree; |
| @@ -179,7 +185,7 @@ getdata( | |||
| 179 | } | 185 | } |
| 180 | } else { | 186 | } else { |
| 181 | printf("Reading tables from file %s\n", filename); | 187 | printf("Reading tables from file %s\n", filename); |
| 182 | size = nissy_datasize(solver); | 188 | size = nissy_solverinfo(solver, dataid); |
| 183 | *buf = malloc(size); | 189 | *buf = malloc(size); |
| 184 | sizeread = fread(*buf, size, 1, f); | 190 | sizeread = fread(*buf, size, 1, f); |
| 185 | fclose(f); | 191 | fclose(f); |
| @@ -203,10 +209,10 @@ gendata_run( | |||
| 203 | uint64_t expected[static 21] | 209 | uint64_t expected[static 21] |
| 204 | ) { | 210 | ) { |
| 205 | long long int size; | 211 | long long int size; |
| 206 | char *buf, filename[1024]; | 212 | char *buf, filename[1024], dataid[NISSY_DATAID_SIZE]; |
| 207 | 213 | ||
| 208 | sprintf(filename, "tables/%s", solver); | 214 | size = generatetable(solver, &buf, dataid); |
| 209 | size = generatetable(solver, &buf); | 215 | sprintf(filename, "tables/%s", dataid); |
| 210 | switch (size) { | 216 | switch (size) { |
| 211 | case -1: | 217 | case -1: |
| 212 | return; | 218 | return; |
