 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
RaptoR
Joined: 27 Jun 2007 Posts: 22 Location: Earth, Cambrian period
|
Posted: Sun May 04, 2008 11:47 am Post subject: |
|
|
Hm, it seems that this simple code hangs AHKA:
| Code: | myarr := AHKANewArray("[A, B, [C1, C2], D, [E1, [E2i, E2ii, E2iii], E3], F]")
|
(I tried to use the latest version, 5.42) |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Sun May 04, 2008 4:55 pm Post subject: |
|
|
That's because it is not correct.
First. To use a string like [A, B, [C1, C2] ... ] requires NON-HEXed AHKArray.
Otherwise, you'll have to say something like [97 ,98, [ ... ] ... ].
Second, AHKANewArray takes either 0 parameters, or 2. Never 1.
If 0, it makes an empty array.
If 2, it works like AHKASplit (see documentation).
If you want to use a string this would work:
| Code: | ; For NON-HEXed AHKArray
myarr := "[A, B, [C1, C2], D, [E1, [E2i, E2ii, E2iii], E3], F]"; |
Or:
| Code: | ; For HEXed AHKArray
myarr := AHKANewArray()
myarr := AHKAAdd(myarr, "A")
myarr := AHKAAdd(myarr, "B")
temp := AHKANewArray()
temp := AHKAAdd(temp, "C1")
temp := AHKAAdd(temp, "C2")
myarr := AHKAAdd(myarr, temp)
myarr := AHKAAdd(myarr, "D")
temp := AHKANewArray()
temp := AHKAAdd(temp, "E1")
temp2 := AHKANewArray()
temp2 := AHKAAdd(temp2, "E2i")
temp2 := AHKAAdd(temp2, "E2ii")
temp2 := AHKAAdd(temp2, "E2iii")
temp := AHKAAdd(temp, temp2)
temp := AHKAAdd(temp, "E3")
myarr := AHKAAdd(myarr, temp)
myarr := AHKAAdd(myarr, "F")
; Note: All of these could be Chained, see Documentation. |
How the 2 param AHKArray works:
| Code: | myarr := AHKANewArray("This is an array", " ")
; myarr = [This,is,an,array] |
|
|
| Back to top |
|
 |
suitedtens
Joined: 28 Apr 2008 Posts: 4
|
Posted: Mon May 05, 2008 6:45 am Post subject: |
|
|
I have another one for you.
Try this (used v5.42):
| Code: | #Include AHKArray.ahk
arr := AHKANewArray()
arr := AHKAAdd(arr, 17)
arr := AHKAAdd(arr, 30)
arr := AHKAAdd(arr, 40)
arr := AHKAAdd(arr, 20)
arr := AHKAAdd(arr, 10)
arr := AHKAAdd(arr, 3)
arr := AHKAAdd(arr, 5)
MsgBox % AHKAMaximum(arr)
MsgBox % AHKAMinimum(arr) |
This gives me a maximum value of 3 and a minimum value of 5.
Looking at the result of the AHKASort that AHKAMaximum/AHKAMinimum use, the sorted array is coming back as:
[5, 10, 17, 20, 30, 40, 3]
Another test case, same array as above but add 11 and 15 to the end (so starting array is [17, 30, 40, 20, 10, 3, 5, 11, 15]):
Now the maximum is 40 but the minimum is 5, and the sorted array comes back as:
[5, 10, 11, 15, 17, 30, 3, 30, 40] |
|
| Back to top |
|
 |
RaptoR
Joined: 27 Jun 2007 Posts: 22 Location: Earth, Cambrian period
|
Posted: Mon May 05, 2008 7:41 am Post subject: |
|
|
| olegbl wrote: | | If you want to use a string this would work: |
Thanks for the explanation.
| olegbl wrote: | | Second, AHKANewArray takes either 0 parameters, or 2. Never 1. |
I found it being kinda strange, because prototype of AHKASplit looks like | Code: | | AHKASplit(String,Char="",CaseSensitive=false) |
where 2 from 3 parameters is optional, therefore passing only 1 parameter to the function is legal  |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Mon May 05, 2008 11:14 pm Post subject: |
|
|
Re-RaptoR
Yeah, sorry, doesn't have that.
I might add the functionality of doing something like:
| Code: | | newArr := AHKANewArray("[1,2,[3a,3b],4]") |
When I have time...
Otherwise, I'll at least make it clear in the documentation, which is why I'm making a new js-powered documentation (which is taking me a lot more time than I thought it would...)
Re-suitedtens
I'll work on the sort bug as soon as I can, the darn quicksort probably got screwed up due to a change of format of some other function... |
|
| Back to top |
|
 |
infogulch
Joined: 27 Mar 2008 Posts: 649
|
Posted: Wed May 07, 2008 3:20 pm Post subject: |
|
|
This is cool. Thnx.
I would like to use it from the lib instead of having to #Include it tho. You'd just have to change the functions to "AHKA_*" from "AHKA*", name the script "AHKA.ahk" and put it in one of the library folders, right? I think that would make it easier on people.
Just an idea. Thanks again!  _________________ Scripts - License |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Wed May 07, 2008 10:34 pm Post subject: |
|
|
Thanks for the suggestion!
I had no idea AHK could use libraries... New feature I guess?
I'll try to use that in the next version, which should come out
around this weekend (hopefully). |
|
| Back to top |
|
 |
infogulch
Joined: 27 Mar 2008 Posts: 649
|
Posted: Thu May 08, 2008 2:38 am Post subject: |
|
|
How about a function like : AHKA_Move(RealArray, IndexFrom= , IndexTo= ) ?
To do this right now I'm doing something like: | Code: | ;Example of moving a variable in AHKA. Move Index 5 to 3:
IndexFrom = 5
IndexTo = 3
sIndex := AHKA_Get(RealArray, IndexFrom)
RealArray := AHKA_Remove(RealArray, IndexFrom)
RealArray := AHKA_Add(RealArray, sIndex, IndexTo) | Similar in concept to Swap, but instead shifts the other variables around the one you're moving.
What do you think? _________________ Scripts - License |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Thu May 08, 2008 3:09 am Post subject: |
|
|
I think that's a good idea, and easy to implement too.
I'll try to put that into the upcoming version as well.
Thanks for the suggestion! |
|
| Back to top |
|
 |
Guest
|
Posted: Thu May 08, 2008 3:19 am Post subject: |
|
|
For the HEX functions, wouldn't this work? Your functions seem longer and more complicated than they need to be.
| Code: | ChrToHex(char)
{
If (StrLen(char) != 1)
{
;ERROR
Return 0
}
IntFormat := A_FormatInteger
SetFormat, Integer, H
char := RegExReplace(asc(char), "^0x", "")
char := StrLen(char) == 1 ? "0" . char : char
SetFormat, Integer, %IntFormat%
Return char
}
ChrFromHex(char)
{
If (StrLen(char) != 2 || !RegExMatch(char, "\d\d"))
{
;ERROR
; Have to return a multi-character string because "0" is an acceptable return value
Return "00"
}
IntFormat := A_FormatInteger
SetFormat, Integer, H
char := chr("0x" . char)
SetFormat, Integer, %IntFormat%
Return char
}
StrToHex(str)
{
Hstr := ""
Loop, parse, str
{
Hchr := ChrToHex(A_LoopField)
If (Hchr == 0)
{
;ERROR
Return 0
}
Hstr .= Hchr
}
Return Hstr
}
StrFromHex(str)
{
If (StrLen(str)/2 != StrLen(str)//2))
{
;ERROR
Return 0
}
Hstr := ""
Loop, parse, str
{
If (A_Index/2 != A_Index//2)
Continue
Hchr := SubStr(A_LoopField, A_Index/2, 2)
Hchr := ChrFromHex(Hchr)
If (Hchr == "00")
{
;ERROR
Return 0
}
Hstr .= Hchr
}
Return Hstr
} |
|
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Thu May 08, 2008 4:18 am Post subject: |
|
|
Yup, that's much better I think.
I didn't look up AHK's HEX function when I was putting mine in.
I changed it, so that'll be updated for next release as well.
Progress:
- HEXing Optimized
- Sorting fixed (rewrote the quicksort)
- Move function implemented
- Changed into AHKA.ahk Library (all functions are now AHKA_* rather than AHKA*)
- Note: For non-Library users: #include AHKA.ahk is still possible
I'll post the new version "officially" as soon as I can get the documentation for it done. For now, I'll put up the "alpha" version XD. PS. It'll jump to v6, since the new documentation thing is a lot of work (too much json), and worth a bunch of update points XD.
<EDIT>
Version 6.00 in it's newest form is downloadable from first post in this topic.
</EDIT>
Thanks to everyone for your support!
Last edited by olegbl on Wed Jul 30, 2008 7:29 pm; edited 1 time in total |
|
| Back to top |
|
 |
olegbl
Joined: 13 Dec 2006 Posts: 48
|
Posted: Thu May 08, 2008 9:52 pm Post subject: |
|
|
| Thanks to infogulch for pointing out that the new HEX function which use SetFormat, only work for integer/float values. The method has been reverted back, and the alpha will now work with all characters. |
|
| Back to top |
|
 |
BLooM2
Joined: 05 May 2008 Posts: 23 Location: China
|
Posted: Sat May 10, 2008 1:59 pm Post subject: |
|
|
thanks it is so useful, expect that you could finish documentation _________________ Fantasy OnLine |
|
| Back to top |
|
 |
fränk Guest
|
Posted: Sat May 24, 2008 7:36 pm Post subject: Performance issues with setting elements in array |
|
|
At first, thanks for the great work. Much more comfortable then these pseudo arrays built into autohotkey.
I have a performance issue with your AHKArray, maybe I am doing something wrong.
I have created an array to which 100 elements are added with AHKAAdd.
Each of that entries is again an array which contains two small strings
I have a function to update one of those 100 elements. The array I'm talking about is the variable called "matrix". "element" is one of the 100 arrays contained in matrix.
| Code: |
SetItemAt(x,y,ByRef element)
{
global numItemsHorz
global matrix
posInMatrix := ((y-1) * numItemsHorz) + x
starttime := a_tickcount
matrix := AHKASet(matrix, element, posInMatrix)
timediff := a_tickcount - starttime
MsgBox, Setting array needed %timediff% ms
}
|
The timediff there is about 1500ms - 1,5 seconds!!
Why is that talking so long?
Isn't your Array Lib meant to be used that way?
Any hints appreciated! |
|
| Back to top |
|
 |
fränk Guest
|
Posted: Sat May 24, 2008 8:22 pm Post subject: |
|
|
Here's some code to reproduce the problem:
| Code: |
arr1Dim := AHKANewArray()
arr2Dim := AHKANewArray()
loop, 100
{
arr1Dim := AHKAAdd(arr1Dim, "test")
arrTemp := AHKANewArray()
arrTemp := AHKAAdd(arrTemp, 17)
arrTemp := AHKAAdd(arrTemp, 71)
arr2Dim := AHKAAdd(arr2Dim, arrTemp)
}
startTime := a_tickcount
arr1Dim := AHKASet(arr1Dim, TEST, 77)
timediff := a_tickcount - starttime
MsgBox, TimeDiff for 1 dimensional array: %timediff% milliseconds
startTime := a_tickcount
arrTemp := AHKANewArray()
arrTemp := AHKAAdd(arrTemp, 66)
arr2Dim := AHKASet(arr2Dim, arrTemp, 77)
timediff := a_tickcount - starttime
MsgBox, TimeDiff for 2 dimensional array: %timediff% milliseconds
#Include AHKArray.ahk
|
Please enlighten me!  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|