[jsword-svn] r1876 - trunk/jsword/src/main/java/org/crosswire/jsword/book/sword

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Fri Jun 13 03:56:31 MST 2008


Author: dmsmith
Date: 2008-06-13 03:56:31 -0700 (Fri, 13 Jun 2008)
New Revision: 1876

Modified:
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java
Log:
fixed an LD binary search bug in RawLDBackend that prevented G000001 from being found.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java	2008-06-11 20:55:40 UTC (rev 1875)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java	2008-06-13 10:56:31 UTC (rev 1876)
@@ -343,6 +343,7 @@
         int total = getCardinality();
         int low = -1;
         int high = total;
+        int match = -1;
 
         while (high - low > 1)
         {
@@ -350,24 +351,29 @@
             int mid = (low + high) >>> 1;
 
             // Get the key for the item at "mid"
-            if (normalizeForSearch(getEntry(key, mid).getKey()).compareTo(target) < 0)
+            int cmp = normalizeForSearch(getEntry(key, mid).getKey()).compareTo(target);
+            if (cmp < 0)
             {
                 low = mid;
             }
-            else
+            else if (cmp > 0)
             {
                 high = mid;
             }
+            else
+            {
+                match = mid;
+                break;
+            }
         }
 
-        // At this point high is what we are what is the candidate.        
-        if (high < total &&  normalizeForSearch(getEntry(key, high).getKey()).compareTo(target) == 0)
+        // Do we have an exact match?
+        if (match >= 0)
         {
-            return high;
+            return match;
         }
 
         // Strong's Greek And Hebrew dictionaries have an introductory entry, so check it for a match.
-        // Get the key for the item at "mid"
         if (normalizeForSearch(getEntry(key, 0).getKey()).compareTo(target) == 0)
         {
             return 0;




More information about the jsword-svn mailing list