aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-09-11 17:01:49 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-09-11 17:01:49 +0200
commite6ff0ce6926fa921a13055c9c35d8e60b691e776 (patch)
tree4af98713a2b43cbd229ca081d2dac877c8c36880 /src
parentdd6078288b5d7af4a4c0cdd1377a2976af569c9a (diff)
downloadnissy-core-e6ff0ce6926fa921a13055c9c35d8e60b691e776.tar.gz
nissy-core-e6ff0ce6926fa921a13055c9c35d8e60b691e776.zip
Finished table refactor
Diffstat (limited to '')
-rw-r--r--src/nissy.c47
-rw-r--r--src/nissy.h6
-rw-r--r--src/solvers/tables.h6
3 files changed, 56 insertions, 3 deletions
diff --git a/src/nissy.c b/src/nissy.c
index de95e94..2d6af4b 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -196,6 +196,53 @@ nissy_datasize(
196} 196}
197 197
198int64_t 198int64_t
199nissy_datainfo(
200 const void *table,
201 void (*write)(const char *, ...)
202)
203{
204 uint8_t i;
205 tableinfo_t info;
206
207 readtableinfo(table, &info);
208
209 write("\n---------\n\n");
210 write("Table information for '%s'\n", info.solver);
211 write("\n");
212 write("Size: %" PRIu64 " bytes\n", info.fullsize);
213 write("Entries: %" PRIu64 " (%" PRIu8 " bits per entry)",
214 info.entries, info.bits);
215 write("\n");
216
217 switch (info.type) {
218 case TABLETYPE_PRUNING:
219 write("\n");
220 if (info.base != 0)
221 write(" (base value = %" PRIu8 ")", info.base);
222 write(":\nValue\tPositions\n");
223 for (i = 0; i <= info.maxvalue; i++) {
224 write("%" PRIu8 "\t%" PRIu64 "\n",
225 i, info.distribution[i]);
226 }
227 break;
228 case TABLETYPE_SPECIAL:
229 write("This is an ad-hoc table\n");
230 break;
231 default:
232 LOG("datainfo: unknown table type\n");
233 return 1;
234 }
235
236 if (info.next != 0) {
237 return nissy_datainfo((char *)table + info.next, write);
238 }
239
240 write("\n---------\n");
241
242 return 0;
243}
244
245int64_t
199nissy_gendata( 246nissy_gendata(
200 const char *solver, 247 const char *solver,
201 const char *options, 248 const char *options,
diff --git a/src/nissy.h b/src/nissy.h
index 346b99a..336130c 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -86,6 +86,12 @@ int64_t nissy_gendata(
86 void *generated_data 86 void *generated_data
87); 87);
88 88
89/* Print information on a data table via the provided callback writer */
90int64_t nissy_datainfo(
91 const void *table,
92 void (*write)(const char *, ...)
93);
94
89/* Returns the number of solutions found, or -1 in case of error */ 95/* Returns the number of solutions found, or -1 in case of error */
90int64_t nissy_solve( 96int64_t nissy_solve(
91 const char cube[static 22], 97 const char cube[static 22],
diff --git a/src/solvers/tables.h b/src/solvers/tables.h
index 44363fe..988de52 100644
--- a/src/solvers/tables.h
+++ b/src/solvers/tables.h
@@ -4,6 +4,9 @@
4#define INFO_SOLVER_STRLEN 100 4#define INFO_SOLVER_STRLEN 100
5#define INFO_DISTRIBUTION_LEN 21 5#define INFO_DISTRIBUTION_LEN 21
6 6
7#define TABLETYPE_PRUNING 0
8#define TABLETYPE_SPECIAL 1
9
7#define INFO_OFFSET_SOLVER 0 10#define INFO_OFFSET_SOLVER 0
8#define INFO_OFFSET_TYPE INFO_SOLVER_STRLEN 11#define INFO_OFFSET_TYPE INFO_SOLVER_STRLEN
9#define INFO_OFFSET_INFOSIZE (INFO_OFFSET_TYPE + sizeof(uint64_t)) 12#define INFO_OFFSET_INFOSIZE (INFO_OFFSET_TYPE + sizeof(uint64_t))
@@ -17,9 +20,6 @@
17#define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t)) 20#define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t))
18#define INFO_OFFSET_DISTRIBUTION (INFO_OFFSET_NEXT + sizeof(uint64_t)) 21#define INFO_OFFSET_DISTRIBUTION (INFO_OFFSET_NEXT + sizeof(uint64_t))
19 22
20const uint64_t TABLETYPE_PRUNING = 0;
21const uint64_t TABLETYPE_SPECIAL = 1;
22
23typedef struct { 23typedef struct {
24 char solver[INFO_SOLVER_STRLEN]; 24 char solver[INFO_SOLVER_STRLEN];
25 uint64_t type; 25 uint64_t type;

Generated with cgit - Back to sebastiano.tronto.net