aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-03-14 16:18:29 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-03-14 16:18:29 +0100
commit1e1fd628207034b0412c50e289f146d34c5baf71 (patch)
treef21715cf39ef5fcc0a9197b214702fb7d16a1c58 /src
parentbfb7b1ab9d2c85a256c42c006060ffe7c2652638 (diff)
downloadnissy-core-1e1fd628207034b0412c50e289f146d34c5baf71.tar.gz
nissy-core-1e1fd628207034b0412c50e289f146d34c5baf71.zip
Replaced datasize with solverinfo
Diffstat (limited to '')
-rw-r--r--src/nissy.c37
-rw-r--r--src/nissy.h14
-rw-r--r--src/solvers/coord/common.h18
-rw-r--r--src/solvers/coord/types_macros.h2
4 files changed, 61 insertions, 10 deletions
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);
20STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]); 20STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]);
21STATIC size_t my_strnlen(const char *, size_t); 21STATIC size_t my_strnlen(const char *, size_t);
22STATIC long long nissy_dataid(const char *, char [static NISSY_DATAID_SIZE]);
22STATIC long long nissy_gendata_unsafe( 23STATIC 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
416STATIC long long
417nissy_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
415long long 437long long
416nissy_datasize( 438nissy_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/*
194Compute the size of the data generated by nissy_gendata, when called with 195Compute the size of the data generated by nissy_gendata when called for
195the same parameters, or -1 in case of error. 196the given solver, and other useful information.
196 197
197Parameters: 198Parameters:
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
200Return values: 205Return 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*/
206long long 211long long
207nissy_datasize( 212nissy_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 *);
7STATIC coord_t *parse_coord(const char *, int); 7STATIC coord_t *parse_coord(const char *, int);
8STATIC uint8_t parse_axis(const char *, int); 8STATIC uint8_t parse_axis(const char *, int);
9STATIC void parse_coord_and_axis(const char *, int, coord_t **, uint8_t *); 9STATIC void parse_coord_and_axis(const char *, int, coord_t **, uint8_t *);
10STATIC int64_t dataid_coord(const char *, char [static NISSY_DATAID_SIZE]);
10 11
11STATIC void 12STATIC void
12append_coord_name(const coord_t *coord, char *str) 13append_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
66STATIC int64_t
67dataid_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
5typedef struct { 5typedef 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 *);

Generated with cgit - Back to sebastiano.tronto.net