I think AHK is great, though I've only used it for a short time. The syntax takes some getting used to for sure.
I've been working on a script and had to look up code for a sort function, and came across several posts. Quicksort written in AHK was pretty slow, and there were differing opinions on sorting.
It would be great if there were a sort of equivalent to some of the C++Std lib functions, particularly sorting and searching. I am unclear on how memory management is handled in AHK, but I can reassign variables that are set to full arrays to be null, and I don't know what happens to the original array. With the stdlib I can forget about memory issues.
Perhaps sorting and searching needs to be on a vector, an (expandable) array with identical types. I like to take a lot of cues from Python lists that can sort any combination of objects, but has a collections module to import. I'm guessing the devs don't want to make AHK as full and complex as Python, but some more simple and common data structures and methods would be very useful. And 2-d arrays could benefit greatly from some searching/sorting features.
Stdlib equivalent Sorting & Searching
-
- Posts: 32
- Joined: 01 Jun 2017, 09:05
Re: Stdlib equivalent Sorting & Searching
What we truly need is some sort of mechanism to share our includes and create standard includes.
Recommends AHK Studio
Re: Stdlib equivalent Sorting & Searching
+1 on wish for sort array functions.
Some comments in list form,
Cheers.
Some comments in list form,
- There is the sort command for sorting strings.
- Search in strings, see InStr and RegExMatch.
- Ahk arrays are automatically expanded, and can hold any type of value, i.e., references to anything.
- For memory issues w.r.t arrays, see reference counting. Eg, myLastReferenceToThisArray:="", now it is gone.
- User function for sorting arrays, Sort dense arrays or matrices.
Since you are interested in Ahk, I'm guessing Python devs don't want to make Python as full and complex as AhkI'm guessing the devs don't want to make AHK as full and complex as Python
Cheers.
-
- Posts: 27
- Joined: 07 Jun 2017, 13:50
Re: Stdlib equivalent Sorting & Searching
A search routine for arrays would be helpful for me too.
@Helgef
Aren't InStr and RegExMatch only for strings and not arrays or even string arrays?
What do you mean by "Ahk arrays are automatically expanded"?
@Helgef
Aren't InStr and RegExMatch only for strings and not arrays or even string arrays?
What do you mean by "Ahk arrays are automatically expanded"?
Re: Stdlib equivalent Sorting & Searching
Hi illuzioner, yes, Instr and RegExMatch operate on strings. Regarding automatic expansion, I refer to the capacity of the array, see SetCapacity.
-
- Posts: 27
- Joined: 07 Jun 2017, 13:50
Re: Stdlib equivalent Sorting & Searching
I see. By "automatic expansion" you mean automatic resizing of arrays.Helgef wrote:Hi illuzioner, yes, Instr and RegExMatch operate on strings. Regarding automatic expansion, I refer to the capacity of the array, see SetCapacity.
Regarding InStr, I think the OP was asking about searching arrays of strings rather than searching in a string. Like in searching ['hello', 'you','world'] to see if the word 'hello' is in the array, rather than searching 'hello' for the letter 'o'.
I agree that searching and sorting are basic but powerful and necessary algorithms for any language. But, you need native implementations for speed and compactness. And having #includes for AutoHotkey libraries that you need seems like a good way to avoid bloat when you compile.
Re: Stdlib equivalent Sorting & Searching
No, with "automatic expansion", I mean "automatic expansion".
Yes, OP is asking for sorting and searching in arrays, not strings. My comments meant to enlight the OP that since Ahk arrays do not have the same benefits as Python's arrays do, it might be worthwhile using strings instead, since these are easily sorted and searched in via built-in functions.
Yes, OP is asking for sorting and searching in arrays, not strings. My comments meant to enlight the OP that since Ahk arrays do not have the same benefits as Python's arrays do, it might be worthwhile using strings instead, since these are easily sorted and searched in via built-in functions.
Re: Stdlib equivalent Sorting & Searching
@Cinemaster: Are you saying that you used the Sort command with a custom function, on a string, and that it was slow? Would you mind giving any further details of the problem? Did you simply have a very large string/number of substrings. Cheers.
For 'searching', I find that using HasKey on an array is pretty good, to check if it has a certain item. Or possibly you could split a large string into smaller ones and search those.
For 'searching', I find that using HasKey on an array is pretty good, to check if it has a certain item. Or possibly you could split a large string into smaller ones and search those.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Who is online
Users browsing this forum: No registered users and 59 guests