COMCTL32: Fix DPA_Search for sorted arrays

Felix Nawothnig felix.nawothnig at t-online.de
Sat Jul 30 17:56:04 CDT 2005


ChangeLog:
Fix DPA_Search for sorted arrays
-------------- next part --------------
Index: dlls/comctl32/tests/dpa.c
===================================================================
RCS file: /home/wine/wine/dlls/comctl32/tests/dpa.c,v
retrieving revision 1.12
diff -u -p -r1.12 dpa.c
--- dlls/comctl32/tests/dpa.c	11 Jul 2005 10:59:42 -0000	1.12
+++ dlls/comctl32/tests/dpa.c	30 Jul 2005 22:55:07 -0000
@@ -274,7 +274,7 @@ static void test_dpa(void)
         j = pDPA_GetPtrIndex(dpa, (PVOID)i);
         ok(j+1 == i, "j=%d i=%d\n", j, i);
         j = pDPA_Search(dpa, (PVOID)i, 0, CB_CmpLT, 0xdeadbeef, DPAS_SORTED);
-        if(i > 1) todo_wine ok(j+1 == i, "j=%d i=%d\n", j, i);
+        ok(j+1 == i, "j=%d i=%d\n", j, i);
 
         /* Linear searches respect iStart ... */
         j = pDPA_Search(dpa, (PVOID)i, i+1, CB_CmpLT, 0xdeadbeef, 0);
Index: dlls/comctl32/dpa.c
===================================================================
RCS file: /home/wine/wine/dlls/comctl32/dpa.c,v
retrieving revision 1.2
diff -u -p -r1.2 dpa.c
--- dlls/comctl32/dpa.c	8 Jul 2005 11:30:28 -0000	1.2
+++ dlls/comctl32/dpa.c	30 Jul 2005 22:55:09 -0000
@@ -787,11 +787,6 @@ BOOL WINAPI DPA_Sort (const HDPA hdpa, P
  * RETURNS
  *     Success: index of the pointer in the array.
  *     Failure: -1
- *
- * NOTES
- *     Binary search taken from R.Sedgewick "Algorithms in C"!
- *     Function is NOT tested!
- *     If something goes wrong, blame HIM not ME! (Eric Kohl)
  */
 INT WINAPI DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
                        PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT uOptions)
@@ -807,47 +802,35 @@ INT WINAPI DPA_Search (const HDPA hdpa, 
         INT l, r, x, n;
         LPVOID *lpPtr;
 
-        TRACE("binary search\n");
-
         l = (nStart == -1) ? 0 : nStart;
         r = hdpa->nItemCount - 1;
         lpPtr = hdpa->ptrs;
         while (r >= l) {
             x = (l + r) / 2;
             n = (pfnCompare)(pFind, lpPtr[x], lParam);
-            if (n < 0)
+            if (n == 0)
+                return x;
+            else if (n < 0)
                 r = x - 1;
-            else
+            else /* (n > 0) */
                 l = x + 1;
-            if (n == 0) {
-                TRACE("-- ret=%d\n", n);
-                return n;
-            }
         }
 
-        if (uOptions & (DPAS_INSERTBEFORE | DPAS_INSERTAFTER)) {
-            TRACE("-- ret=%d\n", l);
-            return l;
-        }
+        return l;
     }
     else {
         /* array is not sorted --> use linear search */
         LPVOID *lpPtr;
         INT  nIndex;
 
-        TRACE("linear search\n");
-
         nIndex = (nStart == -1)? 0 : nStart;
         lpPtr = hdpa->ptrs;
         for (; nIndex < hdpa->nItemCount; nIndex++) {
-            if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0) {
-                TRACE("-- ret=%d\n", nIndex);
+            if ((pfnCompare)(pFind, lpPtr[nIndex], lParam) == 0)
                 return nIndex;
-            }
         }
     }
 
-    TRACE("-- not found: ret=-1\n");
     return -1;
 }
 


More information about the wine-patches mailing list