commit 10b65003102675bd19c0e5174ff249be2a163bc7
parent e6ff0ce6926fa921a13055c9c35d8e60b691e776
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Wed, 11 Sep 2024 19:48:57 +0200
Simplified solver
Diffstat:
7 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/src/nissy.c b/src/nissy.c
@@ -334,7 +334,7 @@ nissy_solve(
ret = -1;
} else {
ret = solve_h48(c, minmoves, maxmoves, maxsolutions,
- h, k, data, solutions);
+ data, solutions);
}
} else if (!strcmp(solver, "h48stats")) {
ret = solve_h48stats(c, maxmoves, data, solutions);
diff --git 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
@@ -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
@@ -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);
@@ -70,6 +74,16 @@ readtableinfo(const void *buf, tableinfo_t *info)
}
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)
{
int i;
@@ -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;
diff --git a/test/090_tables_readwrite/00_table.in b/test/090_tables_readwrite/00_table.in
@@ -6,6 +6,7 @@ Test solver
12345678912345
399999999998
3393
+11
2
0
20
diff --git a/test/090_tables_readwrite/00_table.out b/test/090_tables_readwrite/00_table.out
@@ -6,6 +6,7 @@ Test solver
12345678912345
399999999998
3393
+11
2
0
20
diff --git a/test/090_tables_readwrite/tables_readwrite_tests.c b/test/090_tables_readwrite/tables_readwrite_tests.c
@@ -12,6 +12,7 @@ typedef struct {
uint64_t hash;
uint64_t entries;
uint64_t classes;
+ uint8_t h48h;
uint8_t bits;
uint8_t base;
uint8_t maxvalue;
@@ -47,6 +48,7 @@ tableinfo_t test_readinfo(void) {
ret.hash = readn();
ret.entries = readn();
ret.classes = readn();
+ ret.h48h = (uint8_t)readn();
ret.bits = (uint8_t)readn();
ret.base = (uint8_t)readn();
ret.maxvalue = (uint8_t)readn();
@@ -72,6 +74,7 @@ void test_writeinfo(tableinfo_t info) {
printf("%" PRIu64 "\n", info.hash);
printf("%" PRIu64 "\n", info.entries);
printf("%" PRIu64 "\n", info.classes);
+ printf("%" PRIu8 "\n", info.h48h);
printf("%" PRIu8 "\n", info.bits);
printf("%" PRIu8 "\n", info.base);
printf("%" PRIu8 "\n", info.maxvalue);