nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

utils.h (1154B)


      1 #if SIZE_MAX == UINT64_MAX
      2 #define H48_HMAX UINT8_C(11)
      3 #else
      4 #define H48_HMAX UINT8_C(7)
      5 #endif
      6 
      7 long long parse_h48h(const char *, uint8_t [static 1]);
      8 STATIC long long dataid_h48(const char *, char [static NISSY_SIZE_DATAID]);
      9 
     10 long long
     11 parse_h48h(const char *buf, uint8_t h[static 1])
     12 {
     13 	char format_error_msg[100];
     14 	sprintf(format_error_msg, "[H48] Error parsing H48 solver: must be in "
     15 	    "'h48h*' format, but got '%s'\n", buf);
     16 
     17 	buf += 3;
     18 
     19 	if (*buf != 'h') {
     20 		LOG(format_error_msg);
     21 		goto parse_h48h_error;
     22 	}
     23 	buf++;
     24 
     25 	*h = atoi(buf);
     26 	if (*h > H48_HMAX) {
     27 		LOG("[H48] Invalid value %" PRIu8 " for parameter h (must be "
     28 		     "at most %" PRIu8 ")\n", *h, H48_HMAX);
     29 		goto parse_h48h_error;
     30 	}
     31 
     32 	for ( ; *buf >= 0 + '0' && *buf <= 9 + '0'; buf++) {
     33 		if (*buf == 0) {
     34 			LOG(format_error_msg);
     35 			goto parse_h48h_error;
     36 		}
     37 	}
     38 
     39 	return NISSY_OK;
     40 
     41 parse_h48h_error:
     42 	*h = 0;
     43 	return NISSY_ERROR_INVALID_SOLVER;
     44 }
     45 
     46 STATIC long long
     47 dataid_h48(const char *str, char buf[static NISSY_SIZE_DATAID])
     48 {
     49 	uint8_t h;
     50 	long long err;
     51 
     52 	err = parse_h48h(str, &h);
     53 	if (err < 0)
     54 		return err;
     55 
     56 	sprintf(buf, "h48h%" PRIu8, h);
     57 	return NISSY_OK;
     58 }