From 10b65003102675bd19c0e5174ff249be2a163bc7 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 11 Sep 2024 19:48:57 +0200 Subject: Simplified solver --- src/solvers/h48/gendata_h48.h | 3 ++- src/solvers/h48/solve.h | 14 +++++++++----- src/solvers/tables.h | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 7 deletions(-) (limited to 'src/solvers') diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index f276eca..066c650 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h @@ -152,13 +152,14 @@ gendata_h48(gendata_h48_arg_t *arg) goto gendata_h48_error; } - if (arg->buf == 0) + if (arg->buf == NULL) goto gendata_h48_return_size; if (!readtableinfo(arg->buf, &cocsepinfo)) { LOG("gendata_h48: could not read info for cocsep table\n"); goto gendata_h48_error; } + cocsepinfo.next = cocsepsize; if (!writetableinfo(&cocsepinfo, arg->buf)) { LOG("gendata_h48: could not write info for cocsep table" diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 26847b2..4bf55ca 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h @@ -31,7 +31,7 @@ STATIC uint32_t allowednextmove_h48(uint8_t *, uint8_t, uint32_t); STATIC void solve_h48_appendsolution(dfsarg_solveh48_t *); STATIC_INLINE bool solve_h48_stop(dfsarg_solveh48_t *); STATIC int64_t solve_h48_dfs(dfsarg_solveh48_t *); -STATIC int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, uint8_t, uint8_t, const void *, char *); +STATIC int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, const void *, char *); STATIC int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); STATIC int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); @@ -176,22 +176,26 @@ solve_h48( int8_t minmoves, int8_t maxmoves, int8_t maxsolutions, - uint8_t h, - uint8_t k, const void *data, char *solutions ) { int64_t nsols; dfsarg_solveh48_t arg; + tableinfo_t info; + + if(!readtableinfo_n(data, 2, &info)) { + LOG("solve_h48: error reading table\n"); + return 0; + } arg = (dfsarg_solveh48_t) { .cube = cube, .inverse = inverse(cube), .nsols = &nsols, .maxsolutions = maxsolutions, - .h = h, - .k = k, + .h = info.h48h, + .k = info.bits, .cocsepdata = get_cocsepdata_ptr(data), .h48data = get_h48data_ptr(data), .nextsol = &solutions diff --git a/src/solvers/tables.h b/src/solvers/tables.h index 988de52..bad3b2c 100644 --- a/src/solvers/tables.h +++ b/src/solvers/tables.h @@ -14,7 +14,8 @@ #define INFO_OFFSET_HASH (INFO_OFFSET_FULLSIZE + sizeof(uint64_t)) #define INFO_OFFSET_ENTRIES (INFO_OFFSET_HASH + sizeof(uint64_t)) #define INFO_OFFSET_CLASSES (INFO_OFFSET_ENTRIES + sizeof(uint64_t)) -#define INFO_OFFSET_BITS (INFO_OFFSET_CLASSES + sizeof(uint64_t)) +#define INFO_OFFSET_H48H (INFO_OFFSET_CLASSES + sizeof(uint64_t)) +#define INFO_OFFSET_BITS (INFO_OFFSET_H48H + sizeof(uint8_t)) #define INFO_OFFSET_BASE (INFO_OFFSET_BITS + sizeof(uint8_t)) #define INFO_OFFSET_MAXVALUE (INFO_OFFSET_BASE + sizeof(uint8_t)) #define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t)) @@ -28,6 +29,7 @@ typedef struct { uint64_t hash; uint64_t entries; uint64_t classes; /* Used only by cocsepdata, for now */ + uint8_t h48h; /* Specific to H48 tables */ uint8_t bits; uint8_t base; uint8_t maxvalue; @@ -36,6 +38,7 @@ typedef struct { } tableinfo_t; STATIC bool readtableinfo(const void *, tableinfo_t *); +STATIC bool readtableinfo_n(const void *, uint8_t, tableinfo_t *); STATIC bool writetableinfo(const tableinfo_t *, void *); STATIC bool @@ -59,6 +62,7 @@ readtableinfo(const void *buf, tableinfo_t *info) info->hash = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_HASH); info->entries = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES); info->classes = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES); + info->h48h = *OFFSET(buf, INFO_OFFSET_H48H); info->bits = *OFFSET(buf, INFO_OFFSET_BITS); info->base = *OFFSET(buf, INFO_OFFSET_BASE); info->maxvalue = *OFFSET(buf, INFO_OFFSET_MAXVALUE); @@ -69,6 +73,16 @@ readtableinfo(const void *buf, tableinfo_t *info) return true; } +STATIC bool +readtableinfo_n(const void *buf, uint8_t n, tableinfo_t *info) +{ + for ( ; n > 0; n--, buf = (char *)buf + info->next) + if (!readtableinfo(buf, info)) + return false; + + return true; +} + STATIC bool writetableinfo(const tableinfo_t *info, void *buf) { @@ -98,6 +112,7 @@ writetableinfo(const tableinfo_t *info, void *buf) *(uint64_t *)OFFSET(buf, INFO_OFFSET_HASH) = info->hash; *(uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES) = info->entries; *(uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES) = info->classes; + *OFFSET(buf, INFO_OFFSET_H48H) = info->h48h; *OFFSET(buf, INFO_OFFSET_BITS) = info->bits; *OFFSET(buf, INFO_OFFSET_BASE) = info->base; *OFFSET(buf, INFO_OFFSET_MAXVALUE) = info->maxvalue; -- cgit v1.3