Best method for sorting multiple arrays

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Almost_there
Posts: 404
Joined: 30 Sep 2014, 10:32

Best method for sorting multiple arrays

09 Jun 2015, 18:55

Hi.

I'm making a function that is containing 3 arrays, same number of entries.

To make the function as effective as possible I want to be able to exchange the values of index 4 and 5 on all three arrays.

Array one would contain a color code, array two contain x-coordinat of that color and array three contains y-coordinat. The goal of this is when searching for a color code in array one, each time a color code matches, that index (for all three arrays) shift one position down, so that search time for often used colors reduces as much as possible.

Is there a better (faster to compute) way to do this you think?
hd0202
Posts: 61
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: Best method for sorting multiple arrays

10 Jun 2015, 01:15

From your description I get the impression that you use pseudo arrays instead of associative arrays. In the latter you can store all values in one array, you can use the color code as key and have direct access, no shifting or sorting needed.

Hubert
User avatar
MilesAhead
Posts: 230
Joined: 03 Oct 2013, 09:44

Re: Best method for sorting multiple arrays

11 Jun 2015, 05:54

hd0202 wrote:From your description I get the impression that you use pseudo arrays instead of associative arrays. In the latter you can store all values in one array, you can use the color code as key and have direct access, no shifting or sorting needed.

Hubert


+1. The moving of data would take much longer than the built in indexing using the color in an associative array or dictionary. If you had large data sorting with binary search likely would not be able to out perform db code done in actual compiled code.
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
User avatar
Almost_there
Posts: 404
Joined: 30 Sep 2014, 10:32

Re: Best method for sorting multiple arrays

11 Jun 2015, 18:48

Thanks for answers.

I've worked out a solution that works for me. I've using three independent arrays.
Each hit (for a color) - the position (in all three arrays) move one place forward in order to reduce search time for the most recently used colors.

Maybe it's possible to make the code more efficient, but I haven't got an idea on how yet. Maybe you have a better idea.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

hd0202
Posts: 61
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: Best method for sorting multiple arrays

12 Jun 2015, 03:32

This is my suggestion:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Hubert
User avatar
Almost_there
Posts: 404
Joined: 30 Sep 2014, 10:32

Re: Best method for sorting multiple arrays

12 Jun 2015, 17:33

Hi Hubert.

Thanks for an educational example.

Haven't tried your code yet, I miss some skills regarding arrays in AutoHotkey. I hope to get explained the following questions.

Line 11: defaultColorsArray := {}
Is this any different compared to defaultColorsArray := Object()?

Line 13: defaultColorsArray[defaultColorsArray_T[A_Index]] := {"X" : colorPickPosition_X[A_Index], "Y" : colorPickPosition_Y[A_Index]}
Just by reading your code, I see I do simply not have the skills to fully understand. Still I give a try, and I'll be very thankfull for any corrections of what I'm thinking about the code:
I assume you've made a two dimensional array where defaultColorsArray is tha "host array" (please help me with the correct terminology here). It contains three sub-arrays.
However I don't understand the use of the standalone colon and the curly bracets.

Line 11: MouseMove, defaultColorsArray[colorSameValueHEX].X, defaultColorsArray[colorSameValueHEX].Y
This tells me that you've using a two dimensional array, where the color code is actually the key/index.
hd0202
Posts: 61
Joined: 04 Oct 2013, 03:07
Location: Germany near Cologne

Re: Best method for sorting multiple arrays

13 Jun 2015, 04:44

Hi,
Almost_there wrote:Line 11: defaultColorsArray := {}
Is this any different compared to defaultColorsArray := Object()?
No.
Line 13: defaultColorsArray[defaultColorsArray_T[A_Index]] := {"X" : colorPickPosition_X[A_Index], "Y" : colorPickPosition_Y[A_Index]}
I use an associative array where "color code" is the key. It is associated with a value, for which I use a sub-array with two keys: "X" and "Y", all filled from your temporary arrays. For the first three color codes I get :

Key 0x000000 - X 22 - Y 172
Key 0x400000 - X 22 - Y 152
Key 0x800000 - X 22 - Y 129 and so on

For further explanation see the chapter "associoative array" in "object" in the online docu.

Hubert

Return to “Ask For Help”

Who is online

Users browsing this forum: AutoHotKeyFan, Hellbent, imustbeamoron, Pardeep Tariyal and 22 guests