AutoHotkey Community

It is currently May 26th, 2012, 4:04 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 97 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next
Author Message
 Post subject:
PostPosted: May 4th, 2008, 12:47 pm 
Offline

Joined: June 27th, 2007, 9:47 am
Posts: 22
Location: Earth, Cambrian period
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)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 4th, 2008, 5:55 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
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]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 5th, 2008, 7:45 am 
Offline

Joined: April 28th, 2008, 10:04 pm
Posts: 4
I have another one for you. :wink:

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]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 5th, 2008, 8:41 am 
Offline

Joined: June 27th, 2007, 9:47 am
Posts: 22
Location: Earth, Cambrian period
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 :-)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 6th, 2008, 12:14 am 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2008, 4:20 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2008, 11:34 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
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).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 8th, 2008, 3:38 am 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 8th, 2008, 4:09 am 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 8th, 2008, 4:19 am 
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
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 8th, 2008, 5:18 am 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
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 July 30th, 2008, 8:29 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 8th, 2008, 10:52 pm 
Offline

Joined: December 13th, 2006, 7:16 am
Posts: 48
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 10th, 2008, 2:59 pm 
Offline

Joined: May 5th, 2008, 4:37 am
Posts: 23
Location: China
thanks it is so useful, expect that you could finish documentation

_________________
Fantasy OnLine


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 24th, 2008, 8:36 pm 
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!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2008, 9:22 pm 
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! :idea:


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 97 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group