diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-05-19 17:45:14 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-05-19 17:45:14 +0200 |
| commit | 62d87e063318cc4c842b1b2d8c184f48aeaf6659 (patch) | |
| tree | 832bf338232c477975bea69f7370ca13f350fb07 /src/nissy.c | |
| parent | 8b94d135429a9f3253cc7f25a1453b412065c4a0 (diff) | |
| download | nissy-core-62d87e063318cc4c842b1b2d8c184f48aeaf6659.tar.gz nissy-core-62d87e063318cc4c842b1b2d8c184f48aeaf6659.zip | |
Refactored checkdata
Relevant changes include:
- Changed the signature of nissy_checkdata().
- Removed expected_distribution.h from tools; this data is now included
in each solver's src/ code.
- Removed distribution check for cocsep; may add back later.
Diffstat (limited to '')
| -rw-r--r-- | src/nissy.c | 120 |
1 files changed, 7 insertions, 113 deletions
diff --git a/src/nissy.c b/src/nissy.c index 1f929c0..aaa5c2a 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -12,9 +12,6 @@ | |||
| 12 | #include "core/core.h" | 12 | #include "core/core.h" |
| 13 | #include "solvers/solvers.h" | 13 | #include "solvers/solvers.h" |
| 14 | 14 | ||
| 15 | STATIC bool checkdata(const unsigned char *, const tableinfo_t [static 1]); | ||
| 16 | STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], | ||
| 17 | const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); | ||
| 18 | STATIC long long write_result(oriented_cube_t, char [static NISSY_SIZE_CUBE]); | 15 | STATIC long long write_result(oriented_cube_t, char [static NISSY_SIZE_CUBE]); |
| 19 | STATIC long long nissy_dataid(const char *, char [static NISSY_SIZE_DATAID]); | 16 | STATIC long long nissy_dataid(const char *, char [static NISSY_SIZE_DATAID]); |
| 20 | STATIC long long nissy_gendata_unsafe( | 17 | STATIC long long nissy_gendata_unsafe( |
| @@ -30,47 +27,6 @@ struct { | |||
| 30 | GETCUBE_OPTIONS(NULL, NULL) | 27 | GETCUBE_OPTIONS(NULL, NULL) |
| 31 | }; | 28 | }; |
| 32 | 29 | ||
| 33 | STATIC bool | ||
| 34 | checkdata(const unsigned char *buf, const tableinfo_t info[static 1]) | ||
| 35 | { | ||
| 36 | uint64_t distr[INFO_DISTRIBUTION_LEN]; | ||
| 37 | |||
| 38 | if (info->type == TABLETYPE_PRUNING) { | ||
| 39 | getdistribution(buf + INFOSIZE, distr, info); | ||
| 40 | LOG("\n[checkdata] Checking distribution for %s\n", info->solver); | ||
| 41 | return distribution_equal(info->distribution, distr, info->maxvalue); | ||
| 42 | } else { | ||
| 43 | LOG("\n[checkdata] Skipping distribution check for " | ||
| 44 | "special table %s\n", info->solver); | ||
| 45 | return true; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | STATIC bool | ||
| 50 | distribution_equal( | ||
| 51 | const uint64_t expected[static INFO_DISTRIBUTION_LEN], | ||
| 52 | const uint64_t actual[static INFO_DISTRIBUTION_LEN], | ||
| 53 | uint8_t maxvalue | ||
| 54 | ) | ||
| 55 | { | ||
| 56 | int wrong; | ||
| 57 | uint8_t i; | ||
| 58 | |||
| 59 | for (i = 0, wrong = 0; i <= MIN(maxvalue, 20); i++) { | ||
| 60 | if (expected[i] != actual[i]) { | ||
| 61 | wrong++; | ||
| 62 | LOG("[checkdata] Value for depth %" PRIu8 | ||
| 63 | ": expected %" PRIu64 ", found %" PRIu64 "\n", | ||
| 64 | i, expected[i], actual[i]); | ||
| 65 | } else { | ||
| 66 | LOG("[checkdata] Value for depth %" PRIu8 | ||
| 67 | " is correct (%" PRIu64 ")\n", i, actual[i]); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | return wrong == 0; | ||
| 72 | } | ||
| 73 | |||
| 74 | STATIC long long | 30 | STATIC long long |
| 75 | write_result(oriented_cube_t cube, char result[static NISSY_SIZE_CUBE]) | 31 | write_result(oriented_cube_t cube, char result[static NISSY_SIZE_CUBE]) |
| 76 | { | 32 | { |
| @@ -227,55 +183,6 @@ nissy_getcube( | |||
| 227 | return write_result(oc, result); | 183 | return write_result(oc, result); |
| 228 | } | 184 | } |
| 229 | 185 | ||
| 230 | long long | ||
| 231 | nissy_datainfo( | ||
| 232 | uint64_t data_size, | ||
| 233 | const unsigned char data[data_size] | ||
| 234 | ) | ||
| 235 | { | ||
| 236 | uint8_t i; | ||
| 237 | tableinfo_t info; | ||
| 238 | long long ret; | ||
| 239 | |||
| 240 | if ((size_t)data % 8 != 0) { | ||
| 241 | LOG("[datainfo] Error: buffer is not 8-byte aligned\n"); | ||
| 242 | return NISSY_ERROR_DATA; | ||
| 243 | } | ||
| 244 | |||
| 245 | ret = readtableinfo(data_size, data, &info); | ||
| 246 | if (ret != 0) | ||
| 247 | return ret; | ||
| 248 | |||
| 249 | LOG("\n---------\n\n" | ||
| 250 | "Table information for '%s'\n\n" | ||
| 251 | "Size: %" PRIu64 " bytes\n" | ||
| 252 | "Entries: %" PRIu64 " (%" PRIu8 " bits per entry)\n", | ||
| 253 | info.solver, info.fullsize, info.entries, info.bits); | ||
| 254 | |||
| 255 | switch (info.type) { | ||
| 256 | case TABLETYPE_PRUNING: | ||
| 257 | LOG("\nTable distribution:\nValue\tPositions\n"); | ||
| 258 | for (i = 0; i <= info.maxvalue; i++) { | ||
| 259 | LOG("%" PRIu8 "\t%" PRIu64 "\n", | ||
| 260 | i + info.base, info.distribution[i]); | ||
| 261 | } | ||
| 262 | break; | ||
| 263 | case TABLETYPE_SPECIAL: | ||
| 264 | LOG("This is an ad-hoc table\n"); | ||
| 265 | break; | ||
| 266 | default: | ||
| 267 | LOG("datainfo: unknown table type\n"); | ||
| 268 | return NISSY_ERROR_DATA; | ||
| 269 | } | ||
| 270 | |||
| 271 | if (info.next != 0) | ||
| 272 | return nissy_datainfo(data_size - info.next, data + info.next); | ||
| 273 | |||
| 274 | LOG("\n---------\n"); | ||
| 275 | |||
| 276 | return NISSY_OK; | ||
| 277 | } | ||
| 278 | |||
| 279 | STATIC long long | 186 | STATIC long long |
| 280 | nissy_dataid(const char *solver, char dataid[static NISSY_SIZE_DATAID]) | 187 | nissy_dataid(const char *solver, char dataid[static NISSY_SIZE_DATAID]) |
| 281 | { | 188 | { |
| @@ -344,33 +251,20 @@ nissy_gendata_unsafe( | |||
| 344 | 251 | ||
| 345 | long long | 252 | long long |
| 346 | nissy_checkdata( | 253 | nissy_checkdata( |
| 254 | const char *solver, | ||
| 347 | unsigned long long data_size, | 255 | unsigned long long data_size, |
| 348 | const unsigned char data[data_size] | 256 | const unsigned char data[data_size] |
| 349 | ) | 257 | ) |
| 350 | { | 258 | { |
| 351 | tableinfo_t info; | 259 | solver_dispatch_t *dispatch; |
| 352 | int64_t err; | ||
| 353 | |||
| 354 | if ((size_t)data % 8 != 0) { | ||
| 355 | LOG("[checkdata] Error: buffer is not 8-byte aligned\n"); | ||
| 356 | return NISSY_ERROR_DATA; | ||
| 357 | } | ||
| 358 | |||
| 359 | for (const unsigned char *buf = data; | ||
| 360 | (err = readtableinfo(data_size, buf, &info)) == NISSY_OK; | ||
| 361 | buf += info.next, data_size -= info.next) | ||
| 362 | { | ||
| 363 | if (!checkdata(buf, &info)) { | ||
| 364 | LOG("[checkdata] Error: data for solver '%s' is " | ||
| 365 | "corrupted!\n", info.solver); | ||
| 366 | return NISSY_ERROR_DATA; | ||
| 367 | } | ||
| 368 | 260 | ||
| 369 | if (info.next == 0) | 261 | dispatch = match_solver(solver); |
| 370 | break; | 262 | if (dispatch == NULL) { |
| 263 | LOG("[checkdata] Unknown solver %s\n", solver); | ||
| 264 | return NISSY_ERROR_INVALID_SOLVER; | ||
| 371 | } | 265 | } |
| 372 | 266 | ||
| 373 | return err; | 267 | return dispatch->checkdata(solver, data_size, data); |
| 374 | } | 268 | } |
| 375 | 269 | ||
| 376 | long long | 270 | long long |
