a sorted! array the comparison function by name as string the item's value to look for some optional user data (can be vbnull)
the item's index in the array or -1 if not found
| |
|
|
| |
Implementation
01 function array_search( array_object, comparison_function, lookup_item, user_data )
02 dim lo: lo = lbound( array_object )
03 dim hi: hi = ubound( array_object )
04 do
05 dim half: half = lo + ( ( hi - lo ) \ 2 )
06 dim result: result = eval( comparison_function + "( array_object( half ), lookup_item, user_data )" ) > 0
07 if( result = 0 ) then
08 array_search = half
09 exit function
10 elseif( result > 0 ) then
11 hi = half
12 if( lo = hi ) then
13 exit do
14 end if
15 else
16 lo = half
17 if( lo > hi ) then
18 exit do
19 end if
20 end if
21 loop
22 array_search = -1
23 end function
|
|
| |
|
|
|