From 7812684339d03f6993882358b0045c1bc2d5032c Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 13 Jun 2024 21:08:38 +0200 Subject: Added "dryrun" for gendata --- TODO.txt | 1 - src/cube.h | 12 +++++++++++- src/cube_public.h | 12 ++++++++++++ src/solve_h48.h | 11 ++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/TODO.txt b/TODO.txt index f0c81a6..614e8e5 100644 --- 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 index ab8e964..0eedfec 100644 --- 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 index 1b0cc14..01b6dac 100644 --- 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 @@ -126,6 +128,16 @@ nissy_writecube( return nissy_convertcube("B32", format, cube, result); } +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, diff --git a/src/solve_h48.h b/src/solve_h48.h index 8691d49..8be67b6 100644 --- 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; } -- cgit v1.3