Stdlib equivalent Sorting & Searching

Propose new features and changes
Cinemaster
Posts: 32
Joined: 01 Jun 2017, 09:05

Stdlib equivalent Sorting & Searching

19 Jun 2017, 17:45

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.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Stdlib equivalent Sorting & Searching

20 Jun 2017, 02:17

What we truly need is some sort of mechanism to share our includes and create standard includes.
Recommends AHK Studio
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Stdlib equivalent Sorting & Searching

20 Jun 2017, 02:28

+1 on wish for sort array functions.
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.
What you can do with Ahk's arrays and Python's vectors/list/arrays differ greatly, you might need to rethink how you organise your data in Ahk.
I'm guessing the devs don't want to make AHK as full and complex as Python
Since you are interested in Ahk, I'm guessing Python devs don't want to make Python as full and complex as Ahk ;)

Cheers.
illuzioner
Posts: 27
Joined: 07 Jun 2017, 13:50

Re: Stdlib equivalent Sorting & Searching

20 Jun 2017, 15:36

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
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Stdlib equivalent Sorting & Searching

20 Jun 2017, 15:50

Hi illuzioner, yes, Instr and RegExMatch operate on strings. Regarding automatic expansion, I refer to the capacity of the array, see SetCapacity.
illuzioner
Posts: 27
Joined: 07 Jun 2017, 13:50

Re: Stdlib equivalent Sorting & Searching

20 Jun 2017, 17:04

Helgef wrote:Hi illuzioner, yes, Instr and RegExMatch operate on strings. Regarding automatic expansion, I refer to the capacity of the array, see SetCapacity.
I see. By "automatic expansion" you mean automatic resizing of arrays.

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.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Stdlib equivalent Sorting & Searching

20 Jun 2017, 17:27

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.

☕
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Stdlib equivalent Sorting & Searching

22 Jun 2017, 12:54

@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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Wish List”

Who is online

Users browsing this forum: RaptorX and 105 guests