aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/coord/gendata_coord.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/solvers/coord/gendata_coord.h')
-rw-r--r--src/solvers/coord/gendata_coord.h134
1 files changed, 134 insertions, 0 deletions
diff --git a/src/solvers/coord/gendata_coord.h b/src/solvers/coord/gendata_coord.h
new file mode 100644
index 0000000..b3932cd
--- /dev/null
+++ b/src/solvers/coord/gendata_coord.h
@@ -0,0 +1,134 @@
1STATIC size_t gendata_coordinate(const coord_t *, void *);
2STATIC size_t gendata_coordinate_name(const char *, void *);
3STATIC tableinfo_t genptable_coordinate(const coord_t *, const void *, uint8_t *);
4STATIC uint8_t get_coord_pval(const coord_t *, const uint8_t *, uint64_t);
5STATIC void set_coord_pval(const coord_t *, uint8_t *, uint64_t, uint8_t);
6
7STATIC size_t
8gendata_coordinate_name(const char *name, void *buf)
9{
10 int i;
11
12 for (i = 0; all_coordinates[i] != NULL; i++)
13 if (strcmp(all_coordinates[i]->name, name) == 0)
14 return gendata_coordinate(all_coordinates[i], buf);
15
16 LOG("Cannot generate data for coordinate '%s': not found\n", name);
17 return 0;
18}
19
20STATIC size_t
21gendata_coordinate(const coord_t *coord, void *buf)
22{
23 uint64_t coord_dsize, tablesize, ninfo;
24 void *pruningbuf, *coord_data;
25 uint8_t *table;
26 tableinfo_t coord_data_info, pruning_info;
27
28 coord_data = buf == NULL ? NULL : ((uint8_t *)buf) + INFOSIZE;
29 coord_dsize = coord->gendata(coord_data);
30 ninfo = coord_dsize == 0 ? 1 : 2;
31 tablesize = DIV_ROUND_UP(coord->max, 2);
32
33 if (buf == NULL)
34 goto gendata_coordinate_return_size;
35
36 if (ninfo == 2) {
37 coord_data_info = (tableinfo_t) {
38 .solver = "coord helper table for ",
39 .type = TABLETYPE_SPECIAL,
40 .infosize = INFOSIZE,
41 .fullsize = INFOSIZE + coord_dsize,
42 .hash = 0, /* TODO */
43 .next = INFOSIZE + coord_dsize,
44
45 /* Unknown / non-applicable values */
46 .entries = 0,
47 .classes = 0,
48 .bits = 0,
49 .base = 0,
50 .maxvalue = 0,
51 };
52
53 append_coord_name(coord, coord_data_info.solver);
54
55 writetableinfo(&coord_data_info, INFOSIZE + coord_dsize, buf);
56
57 pruningbuf = ((uint8_t *)buf) + INFOSIZE + coord_dsize;
58 } else {
59 pruningbuf = buf;
60 }
61
62 table = ((uint8_t *)pruningbuf) + INFOSIZE;
63 pruning_info = genptable_coordinate(coord, coord_data, table);
64 writetableinfo(&pruning_info, INFOSIZE + tablesize, pruningbuf);
65
66gendata_coordinate_return_size:
67 return ninfo * INFOSIZE + coord_dsize + tablesize;
68}
69
70STATIC tableinfo_t
71genptable_coordinate(const coord_t *coord, const void *data, uint8_t *table)
72{
73 uint64_t tablesize, i, j, d, tot;
74 tableinfo_t info;
75 uint8_t m;
76 cube_t c, cc;
77
78 tablesize = DIV_ROUND_UP(coord->max, 2);
79
80 memset(table, 0xFF, tablesize);
81
82 info = (tableinfo_t) {
83 .solver = "coordinate solver for ",
84 .type = TABLETYPE_PRUNING,
85 .infosize = INFOSIZE,
86 .fullsize = INFOSIZE + tablesize,
87 .hash = 0, /* TODO */
88 .entries = coord->max,
89 .classes = 0,
90 .bits = 4,
91 .base = 0,
92 .maxvalue = 0,
93 .next = 0
94 };
95
96 memset(info.distribution, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
97 append_coord_name(coord, info.solver);
98
99 i = coord->coord(SOLVED_CUBE, data);
100 set_coord_pval(coord, table, i, 0);
101 info.distribution[0] = 1;
102 for (d = 1, tot = 1; tot < coord->max; d++) {
103 for (i = 0; i < coord->max; i++) {
104 if (get_coord_pval(coord, table, i) == d-1) {
105 c = coord->cube(i, data);
106 for (m = 0; m < 18; m++) {
107 cc = move(c, m);
108 j = coord->coord(cc, data);
109 if (get_coord_pval(coord, table, j) > d) {
110 set_coord_pval(coord, table, j, d);
111 tot++;
112 info.distribution[d]++;
113 }
114 }
115 }
116 }
117 }
118 info.maxvalue = d-1;
119
120 return info;
121}
122
123STATIC uint8_t
124get_coord_pval(const coord_t *coord, const uint8_t *table, uint64_t i)
125{
126 return (table[COORD_INDEX(i)] & COORD_MASK(i)) >> COORD_SHIFT(i);
127}
128
129STATIC void
130set_coord_pval(const coord_t *coord, uint8_t *table, uint64_t i, uint8_t val)
131{
132 table[COORD_INDEX(i)] = (table[COORD_INDEX(i)] & (~COORD_MASK(i)))
133 | (val << COORD_SHIFT(i));
134}

Generated with cgit - Back to sebastiano.tronto.net