Sign in to follow this  
Followers 0
Morthawt

_ArrayBinarySearch "undefined results will be returned" ?

7 posts in this topic

I have been looking for the quickest method of searching an array and I came across the fact that _ArraySearch was slower than a for loop. But I found _ArrayBinarySearch was incredibly incredibly fast. It seemed like the perfect solution except that I have had all kinds of issues. Everything looks logically correct. I added an _ArraySort right before my use of _ArrayBinarySearch and it works perfectly. The only problem is when I have large arrays the sorting process really cramps the speed massively.

How can I use _ArrayBinarySearch without having to perform a _ArraySort and what does the help file mean when it says

"When performing a binary search on an array of items, the contents MUST be sorted before the search is done.

Otherwise undefined results will be returned."

 

Undefined results?

Share this post


Link to post
Share on other sites



You can't use _ArrayBinarySearch unless the array is sorted.

The way the binary search works is, it takes your array and divides it in half, looks to see if what you're searching for is higher or lower than that point. If higher, it divides the second half of the array in half and searches again. If what you're looking for is lower than that point it searches from the halfway point to the 3/4 point and so on and so on. 

So, if it's not sorted, it either can't find what you're looking for, or it will take longer than a standard search would.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

You could cheat. I was on a kick a couple years ago offering up some _Arraysearch() replacements that used Assign(), IsDeclared() and Eval() and were blazingly fast.  I'm sure other have written them too, but about the first 6 results of an advanced search on "_Arraysearch" with me as the author will provide you with a few examples.  I say cheat because, although it works like magic, it's not the intended use of those commands, and using them that way makes me want to hide from anyone I see who is carrying anything even vaguely resembling a "Standards Manual".

Share this post


Link to post
Share on other sites

There's even a trak ticket in that if dealt with would negate that use of Assign and IsDeclared for an array search/array unique style function.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

There's even a trak ticket in that if dealt with would negate that use of Assign and IsDeclared for an array search/array unique style function.

 

It would help if you provided a link.

Share this post


Link to post
Share on other sites

The track ticket is here - #2478


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks for the link BrewManNH. Now I see what you are talking about. Funny ticket. :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0