From 388b55b4ea644aa1b6074a70652b8f62e7755280 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 27 Sep 2024 09:11:00 +0200 Subject: Use constant instead of magic number --- src/nissy.c | 10 +++++----- src/solvers/h48/gendata_h48.h | 20 ++++++++------------ 2 files changed, 13 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/nissy.c b/src/nissy.c index 953471f..2eed1b5 100644 --- a/src/nissy.c +++ b/src/nissy.c @@ -13,8 +13,8 @@ int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); STATIC int64_t write_result(cube_t, char [static 22]); -STATIC bool distribution_equal( - const uint64_t [static 21], const uint64_t [static 21], uint8_t); +STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], + const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); STATIC bool checkdata(const void *, const tableinfo_t *); /* TODO: add option to get DR, maybe C-only, E-only, eo... */ @@ -68,7 +68,7 @@ parse_h48_options_error: STATIC bool checkdata(const void *buf, const tableinfo_t *info) { - uint64_t distr[21]; + uint64_t distr[INFO_DISTRIBUTION_LEN]; if (!strncmp(info->solver, "cocsep", 6)) { getdistribution_cocsep( @@ -86,8 +86,8 @@ checkdata(const void *buf, const tableinfo_t *info) STATIC bool distribution_equal( - const uint64_t expected[static 21], - const uint64_t actual[static 21], + const uint64_t expected[static INFO_DISTRIBUTION_LEN], + const uint64_t actual[static INFO_DISTRIBUTION_LEN], uint8_t maxvalue ) { diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 48d5582..b1ae38c 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h @@ -104,8 +104,8 @@ STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *); STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); STATIC void * gendata_h48k2_runthread(void *); STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *); -STATIC void getdistribution_h48( - const uint8_t *, uint64_t [static 21], uint8_t, uint8_t); +STATIC void getdistribution_h48(const uint8_t *, + uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t); STATIC uint32_t *get_cocsepdata_ptr(const void *); STATIC uint8_t *get_h48data_ptr(const void *); @@ -671,14 +671,14 @@ makeinfo_h48k2(gendata_h48_arg_t *arg) STATIC void getdistribution_h48( const uint8_t *table, - uint64_t distr[static 21], + uint64_t distr[static INFO_DISTRIBUTION_LEN], uint8_t h, uint8_t k ) { uint8_t val; int64_t i, h48max; - memset(distr, 0, 21 * sizeof(uint64_t)); + memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); h48max = H48_COORDMAX(h); for (i = 0; i < h48max; i++) { @@ -725,12 +725,13 @@ size_t gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) { size_t cocsepsize, h48size; - uint8_t val_full, val_derive, val_new, *h48full, *h48derive; + uint8_t val_full, val_derive, *h48full, *h48derive; int64_t i, j, h48max; gendata_h48_arg_t arg; tableinfo_t cocsepinfo, fulltableinfo; /* Initializing values in case of error */ + /* TODO cleanup this */ fulltableinfo.bits = 2; fulltableinfo.base = 8; @@ -777,15 +778,10 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) j = i >> (int64_t)(11-h); val_full = get_h48_pval(h48full, i, arg.k); val_derive = get_h48_pval(h48derive, j, arg.k); - val_new = MIN(val_full, val_derive); - set_h48_pval(h48derive, j, arg.k, val_new); + set_h48_pval(h48derive, j, arg.k, MIN(val_full, val_derive)); } - h48max = H48_COORDMAX(h); - for (i = 0; i < h48max; i++) { - val_derive = get_h48_pval(h48derive, i, arg.k); - arg.info.distribution[val_derive]++; - } + getdistribution_h48(h48derive, arg.info.distribution, h, arg.k); if (!writetableinfo(&arg.info, buf)) { LOG("gendata_h48_derive: could not write info for table\n"); -- cgit v1.3