Re: ArrayBinarySearch question...

"valery_vi" <[email protected]>
Newsgroups gmane.comp.windows.autoit.user
Message-ID <[email protected]>
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], <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]
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.