commit 7812684339d03f6993882358b0045c1bc2d5032c
parent b4d33513bd44c82426ef9e3c6daf5b8046672514
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Thu, 13 Jun 2024 21:08:38 +0200
Added "dryrun" for gendata
Diffstat:
4 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/TODO.txt b/TODO.txt
@@ -3,7 +3,6 @@ Solver
More utilities for tables (in cube.h)
- cleanup solve and gendata in cube.h and cube_public.h
- - for tables, a "dryrun" function that only tells you the size needed
- check hash of generated data
Goal: find out which k value is best
diff --git a/src/cube.h b/src/cube.h
@@ -51,6 +51,16 @@ int nissy_convertcube(
char *result
);
+/*
+Returns the size of the data generated by nissy_gendata, when called with
+the same parameters, or -1 in case of error. The returned value can be
+slightly larger than the actual table size.
+*/
+int64_t nissy_datasize(
+ const char *solver,
+ const char *options
+);
+
/* Returns the number of bytes written, or -1 in case of error */
int64_t nissy_gendata(
const char *solver,
@@ -59,7 +69,7 @@ int64_t nissy_gendata(
);
/* Returns the number of solutions found, or -1 in case of error */
-int nissy_solve(
+int64_t nissy_solve(
const char cube[static 22],
const char *solver,
const char *options,
diff --git a/src/cube_public.h b/src/cube_public.h
@@ -1,3 +1,5 @@
+#include "cube.h"
+
int write_result(cube_t, char [static 22]);
int
@@ -127,6 +129,16 @@ nissy_writecube(
}
int64_t
+nissy_datasize(
+ const char *solver,
+ const char *options
+)
+{
+ /* gendata() handles a NULL *data as a "dryrun" request */
+ return nissy_gendata(solver, options, NULL);
+}
+
+int64_t
nissy_gendata(
const char *solver,
const char *options,
diff --git a/src/solve_h48.h b/src/solve_h48.h
@@ -129,6 +129,9 @@ gendata_cocsep(void *buf, uint64_t *selfsim, cube_t *rep)
uint8_t i, j, visited[COCSEP_VISITEDSIZE];
dfsarg_cocsep_t arg;
+ if (buf == NULL)
+ goto gendata_cocsep_return_size;
+
buf32 = (uint32_t *)buf;
info = buf32 + COCSEP_TABLESIZE;
memset(buf32, 0xFF, sizeof(uint32_t) * COCSEP_TABLESIZE);
@@ -165,6 +168,7 @@ gendata_cocsep(void *buf, uint64_t *selfsim, cube_t *rep)
for (j = 0; j < 10; j++)
DBG_LOG("%" PRIu8 ":\t%" PRIu32 "\n", j, info[j+2]);
+gendata_cocsep_return_size:
return COCSEP_FULLSIZE;
}
@@ -234,8 +238,12 @@ gendata_h48(void *buf, uint8_t h, uint8_t maxdepth)
cube_t crep[COCSEP_CLASSES];
size_t cocsepsize, infosize;
- esep_max = (int64_t)ESEP_MAX(h);
+ infosize = 4 * maxdepth;
cocsepsize = gendata_cocsep(buf, selfsim, crep);
+ if (buf == NULL)
+ goto gendata_h48_return_size;
+
+ esep_max = (int64_t)ESEP_MAX(h);
cocsepdata = (uint32_t *)buf;
buf32 = cocsepdata + cocsepsize / 4;
info = buf32 + (ESEP_TABLESIZE(h, k) / sizeof(uint32_t));
@@ -272,6 +280,7 @@ gendata_h48(void *buf, uint8_t h, uint8_t maxdepth)
for (j = 0; j <= info[0]; j++)
DBG_LOG("%" PRIu8 ":\t%" PRIu32 "\n", j, info[j+1]);
+gendata_h48_return_size:
return cocsepsize + ESEP_TABLESIZE(h, k) + infosize;
}