From 1e1fd628207034b0412c50e289f146d34c5baf71 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 14 Mar 2025 16:18:29 +0100 Subject: Replaced datasize with solverinfo --- src/nissy.c | 37 ++++++++++++++++++++++++++++++++----- src/nissy.h | 14 ++++++++++---- src/solvers/coord/common.h | 18 ++++++++++++++++++ src/solvers/coord/types_macros.h | 2 +- 4 files changed, 61 insertions(+), 10 deletions(-) (limited to 'src') 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], const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]); STATIC size_t my_strnlen(const char *, size_t); +STATIC long long nissy_dataid(const char *, char [static NISSY_DATAID_SIZE]); STATIC long long nissy_gendata_unsafe( const char *, unsigned long long, char *); @@ -412,11 +413,37 @@ nissy_datainfo( return NISSY_OK; } +STATIC long long +nissy_dataid(const char *solver, char dataid[static NISSY_DATAID_SIZE]) +{ + if (!strncmp(solver, "h48", 3)) { + uint8_t h, k; + long long err; + if ((err = parse_h48_solver(solver, &h, &k)) != NISSY_OK) + return err; + /* TODO: also check that h and k are admissible */ + else strcpy(dataid, solver); + return err; + /* TODO: do this when moved parser */ + /* return dataid_h48(solver, dataid); */ + } else if (!strncmp(solver, "coord_", 6)) { + return dataid_coord(solver+6, dataid); + } else { + LOG("gendata: unknown solver %s\n", solver); + return NISSY_ERROR_INVALID_SOLVER; + } +} + long long -nissy_datasize( - const char *solver +nissy_solverinfo( + const char *solver, + char dataid[static NISSY_DATAID_SIZE] ) { + long long err; + if ((err = nissy_dataid(solver, dataid)) != NISSY_OK) + return err; + /* gendata() handles a NULL *data as a "dryrun" request */ return nissy_gendata_unsafe(solver, 0, NULL); } @@ -447,7 +474,7 @@ nissy_gendata_unsafe( } if ((size_t)data % 8 != 0) { - LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); + LOG("nissy_gendata: buffere is not 8-byte aligned\n"); return NISSY_ERROR_DATA; } @@ -478,7 +505,7 @@ nissy_checkdata( int64_t err; if ((size_t)data % 8 != 0) { - LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); + LOG("nissy_checkdata: buffere is not 8-byte aligned\n"); return NISSY_ERROR_DATA; } @@ -560,7 +587,7 @@ nissy_solve( } if ((size_t)data % 8 != 0) { - LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); + LOG("nissy_solve: buffere is not 8-byte aligned\n"); return NISSY_ERROR_DATA; } 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'. #define NISSY_SIZE_H48 88U #define NISSY_SIZE_TRANSFORMATION 12U #define NISSY_SIZE_SOLVE_STATS 10U +#define NISSY_DATAID_SIZE 255U /* Flags for NISS options */ #define NISSY_NISSFLAG_NORMAL 1U @@ -191,11 +192,15 @@ nissy_getcube( ); /* -Compute the size of the data generated by nissy_gendata, when called with -the same parameters, or -1 in case of error. +Compute the size of the data generated by nissy_gendata when called for +the given solver, and other useful information. Parameters: solver - The name of the solver. + dataid - An identifier for the data computed for the solver. Different + solver may use equivalent data. This identifier can be used + e.g. as a filename or database key to save and retrieve the + correct data for each solver, without duplication. Return values: NISSY_ERROR_INVALID_SOLVER - The given solver is not known. @@ -204,8 +209,9 @@ Return values: Any value >= 0 - The size of the data, in bytes. */ long long -nissy_datasize( - const char *solver +nissy_solverinfo( + const char *solver, + char dataid[static NISSY_DATAID_SIZE] ); /* 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 *); STATIC coord_t *parse_coord(const char *, int); STATIC uint8_t parse_axis(const char *, int); STATIC void parse_coord_and_axis(const char *, int, coord_t **, uint8_t *); +STATIC int64_t dataid_coord(const char *, char [static NISSY_DATAID_SIZE]); STATIC void 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) if (axis != NULL) *axis = i == n ? UINT8_ERROR : parse_axis(str+i+1, n-i-1); } + +STATIC int64_t +dataid_coord(const char *ca, char dataid[static NISSY_DATAID_SIZE]) +{ + coord_t *c; + + parse_coord_and_axis(ca, strlen(ca), &c, NULL); + + if (c == NULL) { + LOG("dataid_coord: cannot parse coordinate from '%s'\n", ca); + return NISSY_ERROR_INVALID_SOLVER; + } + + strcpy(dataid, c->name); + + return NISSY_OK; +} 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 @@ #define COORD_MASK(i) (UINT8_C(0xF) << COORD_SHIFT(i)) typedef struct { - char name[255]; + const char name[255]; uint64_t (*coord)(cube_t, const void *); cube_t (*cube)(uint64_t, const void *); size_t (*gendata)(void *); -- cgit v1.3