aboutsummaryrefslogtreecommitdiff
path: root/src/nissy.c
diff options
context:
space:
mode:
authorenricotenuti <tenutz_27@outlook.it>2024-09-29 12:42:31 +0200
committerenricotenuti <tenutz_27@outlook.it>2024-09-29 12:42:31 +0200
commit7a52b4cd50a40e4bce919b6bd51203d0e9867141 (patch)
tree95ab133f9771c4791d5c784f1b3d4822b1dd7d3c /src/nissy.c
parent8fcfb3a33fe053ed2032d58ecc0b5d640c155931 (diff)
parent774a824a6c80b5af495f4fb99d98758e3b9f6b81 (diff)
downloadnissy-core-7a52b4cd50a40e4bce919b6bd51203d0e9867141.tar.gz
nissy-core-7a52b4cd50a40e4bce919b6bd51203d0e9867141.zip
Merge remote-tracking branch 'upstream/master'
Merge upstream
Diffstat (limited to 'src/nissy.c')
-rw-r--r--src/nissy.c73
1 files changed, 71 insertions, 2 deletions
diff --git a/src/nissy.c b/src/nissy.c
index a2da73d..44efb83 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -12,8 +12,11 @@
12 12
13#include "nissy.h" 13#include "nissy.h"
14 14
15STATIC int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); 15int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *);
16STATIC int64_t write_result(cube_t, char [static 22]); 16STATIC int64_t write_result(cube_t, char [static 22]);
17STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN],
18 const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t);
19STATIC bool checkdata(const void *, const tableinfo_t *);
17 20
18/* TODO: add option to get DR, maybe C-only, E-only, eo... */ 21/* TODO: add option to get DR, maybe C-only, E-only, eo... */
19#define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } 22#define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F }
@@ -25,7 +28,7 @@ struct {
25 GETCUBE_OPTIONS(NULL, NULL) 28 GETCUBE_OPTIONS(NULL, NULL)
26}; 29};
27 30
28STATIC int 31int
29parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) 32parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth)
30{ 33{
31 bool h_valid, k_valid, maxdepth_valid; 34 bool h_valid, k_valid, maxdepth_valid;
@@ -63,6 +66,52 @@ parse_h48_options_error:
63 return -1; 66 return -1;
64} 67}
65 68
69STATIC bool
70checkdata(const void *buf, const tableinfo_t *info)
71{
72 uint64_t distr[INFO_DISTRIBUTION_LEN];
73
74 if (!strncmp(info->solver, "cocsep", 6)) {
75 getdistribution_cocsep(
76 (uint32_t *)((char *)buf + INFOSIZE), distr);
77 } else if (!strncmp(info->solver, "h48", 3)) {
78 getdistribution_h48((uint8_t *)buf + INFOSIZE, distr,
79 info->h48h, info->bits);
80 } else {
81 LOG("checkdata: unknown solver %s\n", info->solver);
82 return false;
83 }
84
85 return distribution_equal(info->distribution, distr, info->maxvalue);
86}
87
88STATIC bool
89distribution_equal(
90 const uint64_t expected[static INFO_DISTRIBUTION_LEN],
91 const uint64_t actual[static INFO_DISTRIBUTION_LEN],
92 uint8_t maxvalue
93)
94{
95 int wrong;
96 uint8_t i;
97
98 for (i = 0, wrong = 0; i <= MAX(maxvalue, 20); i++) {
99 if (expected[i] != actual[i]) {
100 wrong++;
101 LOG("Value %" PRIu8 ": expected %" PRIu64 ", found %"
102 PRIu64 "\n", i, expected[i], actual[i]);
103 }
104 }
105
106 if (wrong > 0) {
107 LOG("checkdata: %d wrong values\n", wrong);
108 } else {
109 LOG("checkdata: table is consistent with info\n");
110 }
111
112 return wrong > 0;
113}
114
66STATIC int64_t 115STATIC int64_t
67write_result(cube_t cube, char result[static 22]) 116write_result(cube_t cube, char result[static 22])
68{ 117{
@@ -276,6 +325,26 @@ nissy_gendata(
276} 325}
277 326
278int64_t 327int64_t
328nissy_checkdata(
329 const char *solver,
330 const char *options,
331 const void *data
332)
333{
334 char *buf;
335 tableinfo_t info;
336
337 for (buf = (char *)data; readtableinfo(buf, &info); buf += info.next) {
338 if (!checkdata(buf, &info))
339 return 1;
340 if (info.next == 0)
341 break;
342 }
343
344 return 0;
345}
346
347int64_t
279nissy_solve( 348nissy_solve(
280 const char cube[static 22], 349 const char cube[static 22],
281 const char *solver, 350 const char *solver,

Generated with cgit - Back to sebastiano.tronto.net