furrycow Posted February 4, 2010 Share Posted February 4, 2010 OK, so this is killing me... I have a 1D array which is ~190000 indexes long. It has all been sorted using _ArraySort(), however, when i use _ArrayBinarySearch() it cannot find any value I put into it; giving an @ERROR output of 2, which by the helpfile says that... _ArrayBinarySearch(Const ByRef $avArray, $vValue[, $iStart = 0[, $iEnd = 0]]) @ERROR: 2 - [b]$vValue outside of array's min/max values[/b] What does this actually mean?? The value i am searching for, i know exists 100%, yet it cannot find it. A sample of the sorted data in the array looks something like: 1000010582494 100003156 100003874824478 100005183091 1000071928702 10001123902 100011716431 1000121507 10001321465905 10001365 If i use _ArraySearch() then it finds it fine; but with such a large collection of data, it is bound to be quicker using _ArrayBinarySearch(). Thanks in advance, if you can shed any light on this! Instant Lockerz Invite - www.instantlockerzinvite.co.uk Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2010 Moderators Share Posted February 4, 2010 furrycow,Your array does not look sorted to me if that sample is anything to go by. When I put some of your values in the _ArrayBinarySearch example, this is the sorted array I get:[0]|10001365 [1]|100003156 [2]|1000121507 [3]|100005183091 [4]|100011716431 [5]|100011716549 [6]|1000010582494 [7]|1000071928702 [8]|10001321465905 [9]|100003874824478It is hardly surprising if you get an "out-of-range" error if you use this function when the elements are not ordered.Are you sure _ArraySort is doing its job? have you compared the arrays (or at least part of them ) before and after?M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 4, 2010 Share Posted February 4, 2010 The @error = 2 means your search term is less than the value in the first index or more than the value in the last index. Since the array has to be sorted before the search, that means there is no match IF the array was sorted properly beforehand.That array is NOT sorted properly for use with _ArrayBinarySearch(). Should be: 10001365 100003156 1000121507 10001123902 100005183091 100011716431 1000010582494 1000071928702 10001321465905 100003874824478 Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
furrycow Posted February 4, 2010 Author Share Posted February 4, 2010 (edited) Thanks guys for your replies!I had sorted it all using _ArraySort() and it did give me order that which is shown in my original post...and it did look sorted to me, because if you look at them, each digit in each number string less than or equal to that below it.HOWEVER! Even though i had sorted and displayed the array many times...as it always is with me...it now works how you have explained...so in all honesty i have no idea why it did what it did for me.Thanks again for your help Psalty and Melba....now just to let my old P4 sort out the 190000 values again...its in for a rough night......i need a new computer.EDIT! Aha, i see why it wasnt working for me..they were strings! So it wasnt treating them as a number when it came to sorting it. Edited February 4, 2010 by furrycow Instant Lockerz Invite - www.instantlockerzinvite.co.uk Link to comment Share on other sites More sharing options...
furrycow Posted February 4, 2010 Author Share Posted February 4, 2010 OK, so sorry to carry on like this, but from what i have discovered... I am getting my ~190000 array list from a txt file, and using the following: $NumLIST = StringSplit(StringStripCR(FileRead(@DesktopDir & "\NumlistTEST.txt")),@LF) To put the whole list into an array..but of course then every indexed item in that array is treated as a string, so when i sort that array, it sorts it treating every item as a string rather than a number (even though every value is numerical). Is there any way to read the values from a txt file, whilst keeping them as a number rather than a string, and not by using FileReadLine()? As this would take yonks! I admit the StringSplit() is not going to be doing me any favours in making the outcome not a string, but any ideas? Thanks again! Instant Lockerz Invite - www.instantlockerzinvite.co.uk Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2010 Moderators Share Posted February 4, 2010 furrycow, Just convert all the strings to numbers before sorting like this: #include <Array.au3> $sData = "10001321465905" & @CRLF $sData &= "1000071928702" & @CRLF $sData &= "1000121507" & @CRLF $sData &= "100011716431" & @CRLF $sData &= "100003156" & @CRLF $sData &= "10001365" & @CRLF $sData &= "100005183091" & @CRLF $sData &= "100011716549" & @CRLF $sData &= "100003874824478" $avArray = StringSplit(StringStripCR($sData),@LF) ; display unsorted array _ArrayDisplay($avArray, "$avArray BEFORE _ArraySort()") ; Convert strings to numbers For $i = 1 To $avArray[0] $avArray[$i] = Number($avArray[$i]) Next ; sort the array to be able to do a binary search _ArraySort($avArray) ; display sorted array _ArrayDisplay($avArray, "$avArray AFTER _ArraySort()") ; lookup existing entry $iKeyIndex = _ArrayBinarySearch($avArray, 100003156) ; <<<<<<<<<<<<< make sure this is a number too!!!!!!!!!! If Not @error Then MsgBox(0,'Entry found',' Index: ' & $iKeyIndex) Else MsgBox(0,'Entry Not found',' Error: ' & @error) EndIf M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
furrycow Posted February 4, 2010 Author Share Posted February 4, 2010 Works a treat! Thanks for all your help Melba! Instant Lockerz Invite - www.instantlockerzinvite.co.uk Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now