chiark / gitweb /
{n,m}_max_frags: fix fencepost efficiency problem
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 9 Mar 2014 11:37:14 +0000 (11:37 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 9 Mar 2014 12:22:04 +0000 (12:22 +0000)
fixes the bug discovered/exacerbated in 41013cb05383

main.c

diff --git a/main.c b/main.c
index de880e9..11bdf0f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -119,8 +119,18 @@ static void progress_eol(void) {
 
 static void set_best(double new_best) {
   best = new_best;
-  n_max_frags = floor(n / best);
-  m_max_frags = floor(m / best);
+  /*
+   * When computing n_max_frags, we want to set a value that will skip
+   * anything that won't provide strictly better solutions.  So we
+   * want
+   *             frags <      n / best
+   *                        _          _
+   *   <=>       frags <   |  n / best  |
+   *                        _          _
+   *   <=>       frags <=  |  n / best  | - 1
+   */
+  n_max_frags = ceil(n / best) - 1;
+  m_max_frags = ceil(m / best) - 1;
 }
 
 /*----- multicore support -----*/