Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
9fb00ff5
Commit
9fb00ff5
authored
Aug 01, 2005
by
Felix Nawothnig
Committed by
Alexandre Julliard
Aug 01, 2005
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix DPA_Search for sorted arrays.
parent
d15e2f14
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
24 deletions
+7
-24
dpa.c
dlls/comctl32/dpa.c
+6
-23
dpa.c
dlls/comctl32/tests/dpa.c
+1
-1
No files found.
dlls/comctl32/dpa.c
View file @
9fb00ff5
...
@@ -787,11 +787,6 @@ BOOL WINAPI DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
...
@@ -787,11 +787,6 @@ BOOL WINAPI DPA_Sort (const HDPA hdpa, PFNDPACOMPARE pfnCompare, LPARAM lParam)
* RETURNS
* RETURNS
* Success: index of the pointer in the array.
* Success: index of the pointer in the array.
* Failure: -1
* 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
,
INT
WINAPI
DPA_Search
(
const
HDPA
hdpa
,
LPVOID
pFind
,
INT
nStart
,
PFNDPACOMPARE
pfnCompare
,
LPARAM
lParam
,
UINT
uOptions
)
PFNDPACOMPARE
pfnCompare
,
LPARAM
lParam
,
UINT
uOptions
)
...
@@ -807,47 +802,35 @@ INT WINAPI DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
...
@@ -807,47 +802,35 @@ INT WINAPI DPA_Search (const HDPA hdpa, LPVOID pFind, INT nStart,
INT
l
,
r
,
x
,
n
;
INT
l
,
r
,
x
,
n
;
LPVOID
*
lpPtr
;
LPVOID
*
lpPtr
;
TRACE
(
"binary search
\n
"
);
l
=
(
nStart
==
-
1
)
?
0
:
nStart
;
l
=
(
nStart
==
-
1
)
?
0
:
nStart
;
r
=
hdpa
->
nItemCount
-
1
;
r
=
hdpa
->
nItemCount
-
1
;
lpPtr
=
hdpa
->
ptrs
;
lpPtr
=
hdpa
->
ptrs
;
while
(
r
>=
l
)
{
while
(
r
>=
l
)
{
x
=
(
l
+
r
)
/
2
;
x
=
(
l
+
r
)
/
2
;
n
=
(
pfnCompare
)(
pFind
,
lpPtr
[
x
],
lParam
);
n
=
(
pfnCompare
)(
pFind
,
lpPtr
[
x
],
lParam
);
if
(
n
<
0
)
if
(
n
==
0
)
return
x
;
else
if
(
n
<
0
)
r
=
x
-
1
;
r
=
x
-
1
;
else
else
/* (n > 0) */
l
=
x
+
1
;
l
=
x
+
1
;
if
(
n
==
0
)
{
TRACE
(
"-- ret=%d
\n
"
,
n
);
return
n
;
}
}
}
if
(
uOptions
&
(
DPAS_INSERTBEFORE
|
DPAS_INSERTAFTER
))
{
return
l
;
TRACE
(
"-- ret=%d
\n
"
,
l
);
return
l
;
}
}
}
else
{
else
{
/* array is not sorted --> use linear search */
/* array is not sorted --> use linear search */
LPVOID
*
lpPtr
;
LPVOID
*
lpPtr
;
INT
nIndex
;
INT
nIndex
;
TRACE
(
"linear search
\n
"
);
nIndex
=
(
nStart
==
-
1
)
?
0
:
nStart
;
nIndex
=
(
nStart
==
-
1
)
?
0
:
nStart
;
lpPtr
=
hdpa
->
ptrs
;
lpPtr
=
hdpa
->
ptrs
;
for
(;
nIndex
<
hdpa
->
nItemCount
;
nIndex
++
)
{
for
(;
nIndex
<
hdpa
->
nItemCount
;
nIndex
++
)
{
if
((
pfnCompare
)(
pFind
,
lpPtr
[
nIndex
],
lParam
)
==
0
)
{
if
((
pfnCompare
)(
pFind
,
lpPtr
[
nIndex
],
lParam
)
==
0
)
TRACE
(
"-- ret=%d
\n
"
,
nIndex
);
return
nIndex
;
return
nIndex
;
}
}
}
}
}
TRACE
(
"-- not found: ret=-1
\n
"
);
return
-
1
;
return
-
1
;
}
}
...
...
dlls/comctl32/tests/dpa.c
View file @
9fb00ff5
...
@@ -274,7 +274,7 @@ static void test_dpa(void)
...
@@ -274,7 +274,7 @@ static void test_dpa(void)
j
=
pDPA_GetPtrIndex
(
dpa
,
(
PVOID
)
i
);
j
=
pDPA_GetPtrIndex
(
dpa
,
(
PVOID
)
i
);
ok
(
j
+
1
==
i
,
"j=%d i=%d
\n
"
,
j
,
i
);
ok
(
j
+
1
==
i
,
"j=%d i=%d
\n
"
,
j
,
i
);
j
=
pDPA_Search
(
dpa
,
(
PVOID
)
i
,
0
,
CB_CmpLT
,
0xdeadbeef
,
DPAS_SORTED
);
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 ... */
/* Linear searches respect iStart ... */
j
=
pDPA_Search
(
dpa
,
(
PVOID
)
i
,
i
+
1
,
CB_CmpLT
,
0xdeadbeef
,
0
);
j
=
pDPA_Search
(
dpa
,
(
PVOID
)
i
,
i
+
1
,
CB_CmpLT
,
0xdeadbeef
,
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment