diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-14 15:12:36 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-14 16:09:31 +0100 |
| commit | bcd52547af58b15868e24f3904e307548d1fd505 (patch) | |
| tree | cda0a871f65575bb15fb4536c7b103c13caf433e /src/solvers/h48/utils.h | |
| parent | 21fdf9697ddfab0a9c082a91ae0a79b1b574774c (diff) | |
| download | nissy-core-bcd52547af58b15868e24f3904e307548d1fd505.tar.gz nissy-core-bcd52547af58b15868e24f3904e307548d1fd505.zip | |
Cleanup, update documentation, fix examples
Diffstat (limited to '')
| -rw-r--r-- | src/solvers/h48/utils.h | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/src/solvers/h48/utils.h b/src/solvers/h48/utils.h index 17f1c94..682eb1d 100644 --- a/src/solvers/h48/utils.h +++ b/src/solvers/h48/utils.h | |||
| @@ -4,22 +4,21 @@ | |||
| 4 | #define H48_HMAX UINT8_C(7) | 4 | #define H48_HMAX UINT8_C(7) |
| 5 | #endif | 5 | #endif |
| 6 | 6 | ||
| 7 | long long parse_h48_hk( | 7 | long long parse_h48h(const char *, uint8_t [static 1]); |
| 8 | const char *, uint8_t [static 1], uint8_t [static 1]); | ||
| 9 | STATIC long long dataid_h48(const char *, char [static NISSY_SIZE_DATAID]); | 8 | STATIC long long dataid_h48(const char *, char [static NISSY_SIZE_DATAID]); |
| 10 | 9 | ||
| 11 | long long | 10 | long long |
| 12 | parse_h48_hk(const char *buf, uint8_t h[static 1], uint8_t k[static 1]) | 11 | parse_h48h(const char *buf, uint8_t h[static 1]) |
| 13 | { | 12 | { |
| 14 | char format_error_msg[100]; | 13 | char format_error_msg[100]; |
| 15 | sprintf(format_error_msg, "[H48] Error parsing H48 solver: must be in " | 14 | sprintf(format_error_msg, "[H48] Error parsing H48 solver: must be in " |
| 16 | "'h48h*k*' format, but got '%s'\n", buf); | 15 | "'h48h*' format, but got '%s'\n", buf); |
| 17 | 16 | ||
| 18 | buf += 3; | 17 | buf += 3; |
| 19 | 18 | ||
| 20 | if (*buf != 'h') { | 19 | if (*buf != 'h') { |
| 21 | LOG(format_error_msg); | 20 | LOG(format_error_msg); |
| 22 | goto parse_h48_hk_error; | 21 | goto parse_h48h_error; |
| 23 | } | 22 | } |
| 24 | buf++; | 23 | buf++; |
| 25 | 24 | ||
| @@ -27,48 +26,33 @@ parse_h48_hk(const char *buf, uint8_t h[static 1], uint8_t k[static 1]) | |||
| 27 | if (*h > H48_HMAX) { | 26 | if (*h > H48_HMAX) { |
| 28 | LOG("[H48] Invalid value %" PRIu8 " for parameter h (must be " | 27 | LOG("[H48] Invalid value %" PRIu8 " for parameter h (must be " |
| 29 | "at most %" PRIu8 ")\n", *h, H48_HMAX); | 28 | "at most %" PRIu8 ")\n", *h, H48_HMAX); |
| 30 | goto parse_h48_hk_error; | 29 | goto parse_h48h_error; |
| 31 | } | 30 | } |
| 32 | 31 | ||
| 33 | for ( ; *buf >= 0 + '0' && *buf <= 9 + '0'; buf++) { | 32 | for ( ; *buf >= 0 + '0' && *buf <= 9 + '0'; buf++) { |
| 34 | if (*buf == 0) { | 33 | if (*buf == 0) { |
| 35 | LOG(format_error_msg); | 34 | LOG(format_error_msg); |
| 36 | goto parse_h48_hk_error; | 35 | goto parse_h48h_error; |
| 37 | } | 36 | } |
| 38 | } | 37 | } |
| 39 | 38 | ||
| 40 | if (*buf != 'k') { | ||
| 41 | LOG(format_error_msg); | ||
| 42 | goto parse_h48_hk_error; | ||
| 43 | } | ||
| 44 | buf++; | ||
| 45 | |||
| 46 | *k = atoi(buf); | ||
| 47 | if (!(*k == 2 || (*k == 4 && *h == 0))) { | ||
| 48 | LOG("[H48] Invalid combinations of values h=%" PRIu8 " and k=%" | ||
| 49 | PRIu8 " for parameters h and k\n", *h, *k); | ||
| 50 | goto parse_h48_hk_error; | ||
| 51 | } | ||
| 52 | |||
| 53 | return NISSY_OK; | 39 | return NISSY_OK; |
| 54 | 40 | ||
| 55 | parse_h48_hk_error: | 41 | parse_h48h_error: |
| 56 | *h = 0; | 42 | *h = 0; |
| 57 | *k = 0; | ||
| 58 | return NISSY_ERROR_INVALID_SOLVER; | 43 | return NISSY_ERROR_INVALID_SOLVER; |
| 59 | } | 44 | } |
| 60 | 45 | ||
| 61 | STATIC long long | 46 | STATIC long long |
| 62 | dataid_h48(const char *hk, char buf[static NISSY_SIZE_DATAID]) | 47 | dataid_h48(const char *str, char buf[static NISSY_SIZE_DATAID]) |
| 63 | { | 48 | { |
| 64 | uint8_t h, k; | 49 | uint8_t h; |
| 65 | long long err; | 50 | long long err; |
| 66 | 51 | ||
| 67 | err = parse_h48_hk(hk, &h, &k); | 52 | err = parse_h48h(str, &h); |
| 68 | if (err < 0) | 53 | if (err < 0) |
| 69 | return err; | 54 | return err; |
| 70 | 55 | ||
| 71 | sprintf(buf, "h48h%" PRIu8 "k%" PRIu8 "%s", h, k, | 56 | sprintf(buf, "h48h%" PRIu8, h); |
| 72 | k == 2 ? "i" : ""); | ||
| 73 | return NISSY_OK; | 57 | return NISSY_OK; |
| 74 | } | 58 | } |
