On 10/21/2011 07:53 PM, Dodji Seketeli wrote:
-  do
+  while (mx - mn>  1)
      {
        md = (mx + mn) / 2;
        if (MAP_START_LOCATION (LINEMAPS_MACRO_MAP_AT (set, md))>  line)
        mn = md;
        else
        mx = md;
-    } while (mx - mn>  1);
+    }
+
+  /* There are cases where mx - mn = 1 and where the map we want is
+     mn.  Let's not miss it.  */
+  if (MAP_START_LOCATION (LINEMAPS_MACRO_MAP_AT (set, mn))<= line)
+      mx = mn;

I think a better fix to your binary search algorithm would be to change

  mn = md;

to be

  mn = md + 1;

since you've eliminated md as a possibility.  And then change the test to

 (mn < mx).

Jason

Reply via email to