aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-09-11 19:48:57 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-09-11 19:48:57 +0200
commit10b65003102675bd19c0e5174ff249be2a163bc7 (patch)
tree10388535f1395f084a1a0456094f90cc2390fc62
parente6ff0ce6926fa921a13055c9c35d8e60b691e776 (diff)
downloadnissy-core-10b65003102675bd19c0e5174ff249be2a163bc7.tar.gz
nissy-core-10b65003102675bd19c0e5174ff249be2a163bc7.zip
Simplified solver
-rw-r--r--src/nissy.c2
-rw-r--r--src/solvers/h48/gendata_h48.h3
-rw-r--r--src/solvers/h48/solve.h14
-rw-r--r--src/solvers/tables.h17
-rw-r--r--test/090_tables_readwrite/00_table.in1
-rw-r--r--test/090_tables_readwrite/00_table.out1
-rw-r--r--test/090_tables_readwrite/tables_readwrite_tests.c3
7 files changed, 33 insertions, 8 deletions
diff --git a/src/nissy.c b/src/nissy.c
index 2d6af4b..d657d8e 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -334,7 +334,7 @@ nissy_solve(
334 ret = -1; 334 ret = -1;
335 } else { 335 } else {
336 ret = solve_h48(c, minmoves, maxmoves, maxsolutions, 336 ret = solve_h48(c, minmoves, maxmoves, maxsolutions,
337 h, k, data, solutions); 337 data, solutions);
338 } 338 }
339 } else if (!strcmp(solver, "h48stats")) { 339 } else if (!strcmp(solver, "h48stats")) {
340 ret = solve_h48stats(c, maxmoves, data, solutions); 340 ret = solve_h48stats(c, maxmoves, data, solutions);
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)
152 goto gendata_h48_error; 152 goto gendata_h48_error;
153 } 153 }
154 154
155 if (arg->buf == 0) 155 if (arg->buf == NULL)
156 goto gendata_h48_return_size; 156 goto gendata_h48_return_size;
157 157
158 if (!readtableinfo(arg->buf, &cocsepinfo)) { 158 if (!readtableinfo(arg->buf, &cocsepinfo)) {
159 LOG("gendata_h48: could not read info for cocsep table\n"); 159 LOG("gendata_h48: could not read info for cocsep table\n");
160 goto gendata_h48_error; 160 goto gendata_h48_error;
161 } 161 }
162
162 cocsepinfo.next = cocsepsize; 163 cocsepinfo.next = cocsepsize;
163 if (!writetableinfo(&cocsepinfo, arg->buf)) { 164 if (!writetableinfo(&cocsepinfo, arg->buf)) {
164 LOG("gendata_h48: could not write info for cocsep table" 165 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);
31STATIC void solve_h48_appendsolution(dfsarg_solveh48_t *); 31STATIC void solve_h48_appendsolution(dfsarg_solveh48_t *);
32STATIC_INLINE bool solve_h48_stop(dfsarg_solveh48_t *); 32STATIC_INLINE bool solve_h48_stop(dfsarg_solveh48_t *);
33STATIC int64_t solve_h48_dfs(dfsarg_solveh48_t *); 33STATIC int64_t solve_h48_dfs(dfsarg_solveh48_t *);
34STATIC int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, uint8_t, uint8_t, const void *, char *); 34STATIC int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, const void *, char *);
35 35
36STATIC int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); 36STATIC int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *);
37STATIC int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); 37STATIC int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]);
@@ -176,22 +176,26 @@ solve_h48(
176 int8_t minmoves, 176 int8_t minmoves,
177 int8_t maxmoves, 177 int8_t maxmoves,
178 int8_t maxsolutions, 178 int8_t maxsolutions,
179 uint8_t h,
180 uint8_t k,
181 const void *data, 179 const void *data,
182 char *solutions 180 char *solutions
183) 181)
184{ 182{
185 int64_t nsols; 183 int64_t nsols;
186 dfsarg_solveh48_t arg; 184 dfsarg_solveh48_t arg;
185 tableinfo_t info;
186
187 if(!readtableinfo_n(data, 2, &info)) {
188 LOG("solve_h48: error reading table\n");
189 return 0;
190 }
187 191
188 arg = (dfsarg_solveh48_t) { 192 arg = (dfsarg_solveh48_t) {
189 .cube = cube, 193 .cube = cube,
190 .inverse = inverse(cube), 194 .inverse = inverse(cube),
191 .nsols = &nsols, 195 .nsols = &nsols,
192 .maxsolutions = maxsolutions, 196 .maxsolutions = maxsolutions,
193 .h = h, 197 .h = info.h48h,
194 .k = k, 198 .k = info.bits,
195 .cocsepdata = get_cocsepdata_ptr(data), 199 .cocsepdata = get_cocsepdata_ptr(data),
196 .h48data = get_h48data_ptr(data), 200 .h48data = get_h48data_ptr(data),
197 .nextsol = &solutions 201 .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 @@
14#define INFO_OFFSET_HASH (INFO_OFFSET_FULLSIZE + sizeof(uint64_t)) 14#define INFO_OFFSET_HASH (INFO_OFFSET_FULLSIZE + sizeof(uint64_t))
15#define INFO_OFFSET_ENTRIES (INFO_OFFSET_HASH + sizeof(uint64_t)) 15#define INFO_OFFSET_ENTRIES (INFO_OFFSET_HASH + sizeof(uint64_t))
16#define INFO_OFFSET_CLASSES (INFO_OFFSET_ENTRIES + sizeof(uint64_t)) 16#define INFO_OFFSET_CLASSES (INFO_OFFSET_ENTRIES + sizeof(uint64_t))
17#define INFO_OFFSET_BITS (INFO_OFFSET_CLASSES + sizeof(uint64_t)) 17#define INFO_OFFSET_H48H (INFO_OFFSET_CLASSES + sizeof(uint64_t))
18#define INFO_OFFSET_BITS (INFO_OFFSET_H48H + sizeof(uint8_t))
18#define INFO_OFFSET_BASE (INFO_OFFSET_BITS + sizeof(uint8_t)) 19#define INFO_OFFSET_BASE (INFO_OFFSET_BITS + sizeof(uint8_t))
19#define INFO_OFFSET_MAXVALUE (INFO_OFFSET_BASE + sizeof(uint8_t)) 20#define INFO_OFFSET_MAXVALUE (INFO_OFFSET_BASE + sizeof(uint8_t))
20#define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t)) 21#define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t))
@@ -28,6 +29,7 @@ typedef struct {
28 uint64_t hash; 29 uint64_t hash;
29 uint64_t entries; 30 uint64_t entries;
30 uint64_t classes; /* Used only by cocsepdata, for now */ 31 uint64_t classes; /* Used only by cocsepdata, for now */
32 uint8_t h48h; /* Specific to H48 tables */
31 uint8_t bits; 33 uint8_t bits;
32 uint8_t base; 34 uint8_t base;
33 uint8_t maxvalue; 35 uint8_t maxvalue;
@@ -36,6 +38,7 @@ typedef struct {
36} tableinfo_t; 38} tableinfo_t;
37 39
38STATIC bool readtableinfo(const void *, tableinfo_t *); 40STATIC bool readtableinfo(const void *, tableinfo_t *);
41STATIC bool readtableinfo_n(const void *, uint8_t, tableinfo_t *);
39STATIC bool writetableinfo(const tableinfo_t *, void *); 42STATIC bool writetableinfo(const tableinfo_t *, void *);
40 43
41STATIC bool 44STATIC bool
@@ -59,6 +62,7 @@ readtableinfo(const void *buf, tableinfo_t *info)
59 info->hash = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_HASH); 62 info->hash = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_HASH);
60 info->entries = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES); 63 info->entries = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES);
61 info->classes = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES); 64 info->classes = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES);
65 info->h48h = *OFFSET(buf, INFO_OFFSET_H48H);
62 info->bits = *OFFSET(buf, INFO_OFFSET_BITS); 66 info->bits = *OFFSET(buf, INFO_OFFSET_BITS);
63 info->base = *OFFSET(buf, INFO_OFFSET_BASE); 67 info->base = *OFFSET(buf, INFO_OFFSET_BASE);
64 info->maxvalue = *OFFSET(buf, INFO_OFFSET_MAXVALUE); 68 info->maxvalue = *OFFSET(buf, INFO_OFFSET_MAXVALUE);
@@ -70,6 +74,16 @@ readtableinfo(const void *buf, tableinfo_t *info)
70} 74}
71 75
72STATIC bool 76STATIC bool
77readtableinfo_n(const void *buf, uint8_t n, tableinfo_t *info)
78{
79 for ( ; n > 0; n--, buf = (char *)buf + info->next)
80 if (!readtableinfo(buf, info))
81 return false;
82
83 return true;
84}
85
86STATIC bool
73writetableinfo(const tableinfo_t *info, void *buf) 87writetableinfo(const tableinfo_t *info, void *buf)
74{ 88{
75 int i; 89 int i;
@@ -98,6 +112,7 @@ writetableinfo(const tableinfo_t *info, void *buf)
98 *(uint64_t *)OFFSET(buf, INFO_OFFSET_HASH) = info->hash; 112 *(uint64_t *)OFFSET(buf, INFO_OFFSET_HASH) = info->hash;
99 *(uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES) = info->entries; 113 *(uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES) = info->entries;
100 *(uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES) = info->classes; 114 *(uint64_t *)OFFSET(buf, INFO_OFFSET_CLASSES) = info->classes;
115 *OFFSET(buf, INFO_OFFSET_H48H) = info->h48h;
101 *OFFSET(buf, INFO_OFFSET_BITS) = info->bits; 116 *OFFSET(buf, INFO_OFFSET_BITS) = info->bits;
102 *OFFSET(buf, INFO_OFFSET_BASE) = info->base; 117 *OFFSET(buf, INFO_OFFSET_BASE) = info->base;
103 *OFFSET(buf, INFO_OFFSET_MAXVALUE) = info->maxvalue; 118 *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
index 579736a..0423662 100644
--- a/test/090_tables_readwrite/00_table.in
+++ b/test/090_tables_readwrite/00_table.in
@@ -6,6 +6,7 @@ Test solver
612345678912345 612345678912345
7399999999998 7399999999998
83393 83393
911
92 102
100 110
1120 1220
diff --git a/test/090_tables_readwrite/00_table.out b/test/090_tables_readwrite/00_table.out
index 579736a..0423662 100644
--- a/test/090_tables_readwrite/00_table.out
+++ b/test/090_tables_readwrite/00_table.out
@@ -6,6 +6,7 @@ Test solver
612345678912345 612345678912345
7399999999998 7399999999998
83393 83393
911
92 102
100 110
1120 1220
diff --git a/test/090_tables_readwrite/tables_readwrite_tests.c b/test/090_tables_readwrite/tables_readwrite_tests.c
index 32d171a..e1c2015 100644
--- a/test/090_tables_readwrite/tables_readwrite_tests.c
+++ b/test/090_tables_readwrite/tables_readwrite_tests.c
@@ -12,6 +12,7 @@ typedef struct {
12 uint64_t hash; 12 uint64_t hash;
13 uint64_t entries; 13 uint64_t entries;
14 uint64_t classes; 14 uint64_t classes;
15 uint8_t h48h;
15 uint8_t bits; 16 uint8_t bits;
16 uint8_t base; 17 uint8_t base;
17 uint8_t maxvalue; 18 uint8_t maxvalue;
@@ -47,6 +48,7 @@ tableinfo_t test_readinfo(void) {
47 ret.hash = readn(); 48 ret.hash = readn();
48 ret.entries = readn(); 49 ret.entries = readn();
49 ret.classes = readn(); 50 ret.classes = readn();
51 ret.h48h = (uint8_t)readn();
50 ret.bits = (uint8_t)readn(); 52 ret.bits = (uint8_t)readn();
51 ret.base = (uint8_t)readn(); 53 ret.base = (uint8_t)readn();
52 ret.maxvalue = (uint8_t)readn(); 54 ret.maxvalue = (uint8_t)readn();
@@ -72,6 +74,7 @@ void test_writeinfo(tableinfo_t info) {
72 printf("%" PRIu64 "\n", info.hash); 74 printf("%" PRIu64 "\n", info.hash);
73 printf("%" PRIu64 "\n", info.entries); 75 printf("%" PRIu64 "\n", info.entries);
74 printf("%" PRIu64 "\n", info.classes); 76 printf("%" PRIu64 "\n", info.classes);
77 printf("%" PRIu8 "\n", info.h48h);
75 printf("%" PRIu8 "\n", info.bits); 78 printf("%" PRIu8 "\n", info.bits);
76 printf("%" PRIu8 "\n", info.base); 79 printf("%" PRIu8 "\n", info.base);
77 printf("%" PRIu8 "\n", info.maxvalue); 80 printf("%" PRIu8 "\n", info.maxvalue);

Generated with cgit - Back to sebastiano.tronto.net