RE: Re: ArrayBinarySearch question...
| Newsgroups | gmane.comp.windows.autoit.user |
|---|---|
| Message-ID | <C3339561D7B7F246B51D79A63BA14BEC01DB8A87@drsse603.eu.infineon.com> |
I ended up just copying the udf to my script and changing all of the places where it reads $avArray[$...] to StringLeft($avArray[$...],7) and it works great. Thanks ________________________________ From: [email protected] [mailto:[email protected]] On Behalf Of valery_vi Sent: Thursday, February 15, 2007 9:07 AM To: [email protected] Subject: [AutoIt] Re: ArrayBinarySearch question... Source of it is following: ;===================================================================== ========== ; ; Function Name: _ArrayBinarySearch() ; Description: Uses the binary search algorithm to search through a ; 1-dimensional array. ; Author(s): Jos van der Zande <jdeb at autoitscript dot com> ; ;===================================================================== ========== Func _ArrayBinarySearch(ByRef $avArray, $sKey, $i_Base = 0) Local $iLwrLimit = $i_Base Local $iUprLimit Local $iMidElement If (Not IsArray($avArray)) Then SetError(1) Return "" EndIf $iUprLimit = UBound($avArray) - 1 $iMidElement = Int( ($iUprLimit + $iLwrLimit) / 2) ; sKey is smaller than the first entry If $avArray[$iLwrLimit] > $sKey Or $avArray[$iUprLimit] < $sKey Then SetError(2) Return "" EndIf While $iLwrLimit <= $iMidElement And $sKey <> $avArray [$iMidElement] If $sKey < $avArray[$iMidElement] Then $iUprLimit = $iMidElement - 1 Else $iLwrLimit = $iMidElement + 1 EndIf $iMidElement = Int( ($iUprLimit + $iLwrLimit) / 2) WEnd If $iLwrLimit > $iUprLimit Then ; Entry not found SetError(3) Return "" Else ;Entry found , return the index SetError(0) Return $iMidElement EndIf EndFunc ;==>_ArrayBinarySearch To search only partial match you have to update lines where $sKey is compared with members of array $avArray[...], I think. Good idea is to use func StringRegExp instead of operators < or >. Valery --- In [email protected] <mailto:AutoItList%40yahoogroups.com> , <marx.external@...> wrote: > > When using the Array Binary Search udf does the $ikey have to match > exactly or is there an ability to search for a partial match? > > > > I have an array that each element looks like this > > 5000124|12|RICSA500SIM > > > > I want to be able to search the array for that first segment 5000124. > > > > $Locater = _ArrayBinarySearch($ComputerInfoDB,$CurrentBI[2]) > > > > Thanks > > > > [Non-text portions of this message have been removed] > [Non-text portions of this message have been removed]