2016-08-31 10:51:59 -07:00
|
|
|
#ifndef RUNTIME_ERROR_COSTS_H_
|
|
|
|
|
#define RUNTIME_ERROR_COSTS_H_
|
|
|
|
|
|
2016-10-05 14:02:49 -07:00
|
|
|
#define ERROR_STATE 0
|
2016-08-31 10:51:59 -07:00
|
|
|
#define ERROR_COST_PER_SKIPPED_TREE 10
|
|
|
|
|
#define ERROR_COST_PER_SKIPPED_LINE 3
|
|
|
|
|
#define ERROR_COST_PER_SKIPPED_CHAR 0
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
unsigned cost;
|
|
|
|
|
unsigned count;
|
2016-08-31 17:29:14 -07:00
|
|
|
unsigned push_count;
|
2016-08-31 10:51:59 -07:00
|
|
|
} ErrorStatus;
|
|
|
|
|
|
2016-09-01 11:39:23 -07:00
|
|
|
static inline unsigned error_status_min_cost(ErrorStatus status) {
|
2016-10-05 14:02:49 -07:00
|
|
|
return status.cost + ERROR_COST_PER_SKIPPED_TREE * status.count * status.count;
|
2016-08-31 17:29:14 -07:00
|
|
|
}
|
2016-08-31 10:51:59 -07:00
|
|
|
|
2016-09-01 11:39:23 -07:00
|
|
|
static inline unsigned error_status_max_cost(ErrorStatus status) {
|
|
|
|
|
return status.cost +
|
2016-10-05 14:02:49 -07:00
|
|
|
ERROR_COST_PER_SKIPPED_TREE * status.count * status.count +
|
|
|
|
|
(6 * ERROR_COST_PER_SKIPPED_TREE * status.count +
|
|
|
|
|
12 * ERROR_COST_PER_SKIPPED_TREE) /
|
|
|
|
|
(1 + status.push_count / 2);
|
2016-09-01 11:39:23 -07:00
|
|
|
}
|
2016-08-31 10:51:59 -07:00
|
|
|
|
2016-09-01 11:39:23 -07:00
|
|
|
static inline int error_status_compare(ErrorStatus a, ErrorStatus b) {
|
|
|
|
|
if ((a.count + 1 < b.count) || (a.count < b.count && a.cost <= b.cost))
|
2016-08-31 10:51:59 -07:00
|
|
|
return -1;
|
2016-09-01 11:39:23 -07:00
|
|
|
if ((a.count > b.count + 1) || (b.count < a.count && b.cost <= a.cost))
|
2016-08-31 10:51:59 -07:00
|
|
|
return 1;
|
|
|
|
|
|
2016-09-01 11:39:23 -07:00
|
|
|
if (error_status_max_cost(a) < error_status_min_cost(b))
|
|
|
|
|
return -1;
|
|
|
|
|
if (error_status_min_cost(a) > error_status_max_cost(b))
|
|
|
|
|
return 1;
|
2016-08-31 10:51:59 -07:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|