aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/coord/checkdata.h
blob: 791761f1336e52bac0c3da70d2239c19a13cbda2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
STATIC long long checkdata_coord(
    const char *, unsigned long long, const unsigned char *);

STATIC long long
checkdata_coord(
	const char *solver,
	unsigned long long data_size,
	const unsigned char *data
)
{
	coord_t *coord;
	const unsigned char *table;
	tableinfo_t info;
	int64_t err;
	uint64_t actual_distribution[INFO_DISTRIBUTION_LEN];

	if ((size_t)data % 8 != 0) {
		LOG("[checkdata] Error: buffer is not 8-byte aligned\n");
		return NISSY_ERROR_DATA;
	}

	parse_coord_and_axis(solver, &coord, NULL);
	if (coord == NULL) {
		LOG("[cehckdata] Unknown coordinate solver '%s'\n", solver);
		return NISSY_ERROR_DATA;
	}

	table = data + INFOSIZE;
	err = readtableinfo(data_size, data, &info);
	if (err != NISSY_OK) {
		LOG("[checkdata] Data is corrupt\n");
		return err;
	}

	if (info.type != TABLETYPE_PRUNING) {
		LOG("[checkdata] Skipping '%s'\n", info.solver);
		table += info.next;
		err = readtableinfo_n(data_size, data, 2, &info);
		if (err != NISSY_OK) {
			LOG("[checkdata] Data is corrupt\n");
			return err;
		}
	}
	
	LOG("[checkdata] Checking distribution for '%s' from "
	    "table preamble\n", info.solver);
	if (!distribution_equal(coord->pruning_distribution,
	    info.distribution, coord->pruning_max)) {
		LOG("[checkdata] Distribution from the table preamble does "
		    "not match the expected one\n");
		return NISSY_ERROR_DATA;
	}

	LOG("\n[checkdata] Checking distribution for '%s' from "
	    "actual table\n", info.solver);
	getdistribution(table, actual_distribution, &info);
	if (!distribution_equal(coord->pruning_distribution,
	    actual_distribution, coord->pruning_max)) {
		LOG("[checkdata] Distribution from the actual table does "
		    "not match the expected one\n");
		return NISSY_ERROR_DATA;
	}

	return NISSY_OK;
}

Generated with cgit - Back to sebastiano.tronto.net