ref: 20b56788bc61de5b3d10c90a9fd588d373134aae
parent: f6965b92e1915c9f49fafbadf603b4fd0da735bd
author: Simon Tatham <anakin@pobox.com>
date: Tue Nov 13 16:39:45 EST 2018
Adopt C99 bool in the edsf API. Now the flag passed to edsf_merge to say whether two items are the same or opposite is a bool, and so is the flag returned via a pointer argument from edsf_canonify. The latter requires client code to be updated to match (otherwise you'll get a pointer type error), so I've done that update in Loopy, which is edsf's only current in-tree client.
--- a/dsf.c
+++ b/dsf.c
@@ -15,7 +15,8 @@
int *equal_elements = snewn(size, int);
int *inverse_elements = snewn(size, int);
int printed_count = 0, equal_count, inverse_count;
- int i, n, inverse;
+ int i, n;
+ bool inverse;
memset(printed_elements, -1, sizeof(int) * size);
@@ -99,10 +100,10 @@
return dsf[dsf_canonify(dsf, index)] >> 2;
}
-int edsf_canonify(int *dsf, int index, int *inverse_return)
+int edsf_canonify(int *dsf, int index, bool *inverse_return)
{
int start_index = index, canonical_index;
- int inverse = 0;
+ bool inverse = false;
/* fprintf(stderr, "dsf = %p\n", dsf); */
/* fprintf(stderr, "Canonify %2d\n", index); */
@@ -141,9 +142,9 @@
return index;
}
-void edsf_merge(int *dsf, int v1, int v2, int inverse)
+void edsf_merge(int *dsf, int v1, int v2, bool inverse)
{
- int i1, i2;
+ bool i1, i2;
/* fprintf(stderr, "dsf = %p\n", dsf); */
/* fprintf(stderr, "Merge [%2d,%2d], %d\n", v1, v2, inverse); */
--- a/loopy.c
+++ b/loopy.c
@@ -1197,15 +1197,15 @@
}
/* Merge two lines because the solver has deduced that they must be either
- * identical or opposite. Returns TRUE if this is new information, otherwise
- * FALSE. */
-static int merge_lines(solver_state *sstate, int i, int j, int inverse
+ * identical or opposite. Returns true if this is new information, otherwise
+ * false. */
+static int merge_lines(solver_state *sstate, int i, int j, bool inverse
#ifdef SHOW_WORKING
, const char *reason
#endif
)
{
- int inv_tmp;
+ bool inv_tmp;
assert(i < sstate->state->game_grid->num_edges);
assert(j < sstate->state->game_grid->num_edges);
@@ -1931,7 +1931,8 @@
grid_face *f = g->faces + face_index;
int N = f->order;
int i, j;
- int can1, can2, inv1, inv2;
+ int can1, can2;
+ bool inv1, inv2;
for (i = 0; i < N; i++) {
int line1_index = f->edges[i] - g->edges;
@@ -1996,7 +1997,7 @@
} else if (unknown_count == 3) {
int e[3];
int can[3]; /* canonical edges */
- int inv[3]; /* whether can[x] is inverse to e[x] */
+ bool inv[3]; /* whether can[x] is inverse to e[x] */
find_unknowns(state, edge_list, 3, e);
can[0] = edsf_canonify(linedsf, e[0], inv);
can[1] = edsf_canonify(linedsf, e[1], inv+1);
@@ -2019,7 +2020,7 @@
} else if (unknown_count == 4) {
int e[4];
int can[4]; /* canonical edges */
- int inv[4]; /* whether can[x] is inverse to e[x] */
+ bool inv[4]; /* whether can[x] is inverse to e[x] */
find_unknowns(state, edge_list, 4, e);
can[0] = edsf_canonify(linedsf, e[0], inv);
can[1] = edsf_canonify(linedsf, e[1], inv+1);
@@ -2627,7 +2628,8 @@
int dline_index = dline_index_from_dot(g, d, j);
int line1_index;
int line2_index;
- int can1, can2, inv1, inv2;
+ int can1, can2;
+ bool inv1, inv2;
int j2;
line1_index = d->edges[j] - g->edges;
if (state->lines[line1_index] != LINE_UNKNOWN)
@@ -2671,7 +2673,8 @@
/* If the state of a line is known, deduce the state of its canonical line
* too, and vice versa. */
for (i = 0; i < g->num_edges; i++) {
- int can, inv;
+ int can;
+ bool inv;
enum line_state s;
can = edsf_canonify(sstate->linedsf, i, &inv);
if (can == i)
--- a/puzzles.h
+++ b/puzzles.h
@@ -435,16 +435,16 @@
/* Return the canonical element of the equivalence class containing element
* val. If 'inverse' is non-NULL, this function will put into it a flag
* indicating whether the canonical element is inverse to val. */
-int edsf_canonify(int *dsf, int val, int *inverse);
+int edsf_canonify(int *dsf, int val, bool *inverse);
int dsf_canonify(int *dsf, int val);
int dsf_size(int *dsf, int val);
/* Allow the caller to specify that two elements should be in the same
- * equivalence class. If 'inverse' is TRUE, the elements are actually opposite
+ * equivalence class. If 'inverse' is true, the elements are actually opposite
* to one another in some sense. This function will fail an assertion if the
* caller gives it self-contradictory data, ie if two elements are claimed to
* be both opposite and non-opposite. */
-void edsf_merge(int *dsf, int v1, int v2, int inverse);
+void edsf_merge(int *dsf, int v1, int v2, bool inverse);
void dsf_merge(int *dsf, int v1, int v2);
void dsf_init(int *dsf, int len);