chiark / gitweb /
Adopt C99 bool in the shared Latin-square API.
authorSimon Tatham <anakin@pobox.com>
Tue, 13 Nov 2018 21:42:28 +0000 (21:42 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 13 Nov 2018 21:48:24 +0000 (21:48 +0000)
latin_check now returns bool, and latin_solver_diff_set takes a bool
'extreme' flag. Should be non-disruptive.

latin.c
latin.h

diff --git a/latin.c b/latin.c
index 6e805455bf712f51ee698033933283de8bbb3e49..3865ad1abf3dbdb2b6d30f301855e405d88f0421 100644 (file)
--- a/latin.c
+++ b/latin.c
@@ -650,7 +650,7 @@ int latin_solver_diff_simple(struct latin_solver *solver)
 
 int latin_solver_diff_set(struct latin_solver *solver,
                           struct latin_solver_scratch *scratch,
-                          int extreme)
+                          bool extreme)
 {
     int x, y, n, ret, o = solver->o;
 #ifdef STANDALONE_SOLVER
@@ -1244,12 +1244,12 @@ static int latin_check_cmp(void *v1, void *v2)
 
 #define ELT(sq,x,y) (sq[((y)*order)+(x)])
 
-/* returns non-zero if sq is not a latin square. */
-int latin_check(digit *sq, int order)
+/* returns true if sq is not a latin square. */
+bool latin_check(digit *sq, int order)
 {
     tree234 *dict = newtree234(latin_check_cmp);
     int c, r;
-    int ret = 0;
+    bool ret = false;
     lcparams *lcp, lc, *aret;
 
     /* Use a tree234 as a simple hash table, go through the square
@@ -1272,10 +1272,10 @@ int latin_check(digit *sq, int order)
 
     /* There should be precisely 'order' letters in the alphabet,
      * each occurring 'order' times (making the OxO tree) */
-    if (count234(dict) != order) ret = 1;
+    if (count234(dict) != order) ret = true;
     else {
        for (c = 0; (lcp = index234(dict, c)) != NULL; c++) {
-           if (lcp->count != order) ret = 1;
+           if (lcp->count != order) ret = true;
        }
     }
     for (c = 0; (lcp = index234(dict, c)) != NULL; c++)
diff --git a/latin.h b/latin.h
index 747cfb61f7b6f10583a66747293f9d67724f19d8..3c9e8e89447116515ff9087df86f88dc8eed68d5 100644 (file)
--- a/latin.h
+++ b/latin.h
@@ -82,7 +82,7 @@ int latin_solver_diff_simple(struct latin_solver *solver);
  * single-number elimination. */
 int latin_solver_diff_set(struct latin_solver *solver,
                           struct latin_solver_scratch *scratch,
-                          int extreme);
+                          bool extreme);
 
 typedef int (*usersolver_t)(struct latin_solver *solver, void *ctx);
 typedef void *(*ctxnew_t)(void *ctx);
@@ -115,7 +115,7 @@ digit *latin_generate(int o, random_state *rs);
 /* The order of the latin rectangle is max(w,h). */
 digit *latin_generate_rect(int w, int h, random_state *rs);
 
-int latin_check(digit *sq, int order); /* !0 => not a latin square */
+bool latin_check(digit *sq, int order); /* true => not a latin square */
 
 void latin_debug(digit *sq, int order);