From 62d87e063318cc4c842b1b2d8c184f48aeaf6659 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 19 May 2025 17:45:14 +0200 Subject: 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. --- src/solvers/coord/checkdata.h | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/solvers/coord/checkdata.h (limited to 'src/solvers/coord/checkdata.h') diff --git a/src/solvers/coord/checkdata.h b/src/solvers/coord/checkdata.h new file mode 100644 index 0000000..81394c7 --- /dev/null +++ b/src/solvers/coord/checkdata.h @@ -0,0 +1,65 @@ +STATIC long long checkdata_coord( + const char *, unsigned long long n, const unsigned char [n]); + +STATIC long long +checkdata_coord( + const char *solver, + unsigned long long data_size, + const unsigned char data[data_size] +) +{ + coord_t *coord; + const unsigned char *table; + tableinfo_t info; + int64_t err; + uint64_t actual_distribution[INFO_DISTRIBUTION_LEN]; + + if ((size_t)data % 8 != 0) { + LOG("[checkdata] Error: buffer is not 8-byte aligned\n"); + return NISSY_ERROR_DATA; + } + + parse_coord_and_axis(solver, &coord, NULL); + if (coord == NULL) { + LOG("[cehckdata] Unknown coordinate solver '%s'\n", solver); + return NISSY_ERROR_DATA; + } + + table = data + INFOSIZE; + err = readtableinfo(data_size, data, &info); + if (err != NISSY_OK) { + LOG("[checkdata] Data is corrupt\n"); + return err; + } + + if (info.type != TABLETYPE_PRUNING) { + LOG("[checkdata] Skipping '%s'\n", info.solver); + table += info.next; + err = readtableinfo_n(data_size, data, 2, &info); + if (err != NISSY_OK) { + LOG("[checkdata] Data is corrupt\n"); + return err; + } + } + + LOG("[checkdata] Checking distribution for '%s' from " + "table preamble\n", info.solver); + if (!distribution_equal(coord->pruning_distribution, + info.distribution, coord->pruning_max)) { + LOG("[checkdata] Distribution from the table preamble does " + "not match the expected one\n"); + return NISSY_ERROR_DATA; + } + + LOG("\n[checkdata] Checking distribution for '%s' from " + "actual table\n", info.solver); + getdistribution(table, actual_distribution, &info); + if (!distribution_equal(coord->pruning_distribution, + actual_distribution, coord->pruning_max)) { + LOG("[checkdata] Distribution from the actual table does " + "not match the expected one\n"); + return NISSY_ERROR_DATA; + } + + return NISSY_OK; +} -- cgit v1.3