AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

AHKArray [Real Array - One Variable] [Version 5]
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
olegbl



Joined: 13 Dec 2006
Posts: 19

PostPosted: Sun Apr 01, 2007 6:02 pm    Post subject: Reply with quote

Ok, 5.37 is out...
Hopefully there aren't too many bugs.
HEXing has been implemented, see documentation (can be easily removed).
Added some functions...
Overloaded the Get() function to accept up to 10 indexes.
Code:
Var := AHKAGet(Array,X,Y,Z) ;etc

Please let me know if you find any bugs.

PS. Numberical sorting works with the AHKASort() function IF the numbers in the array are numbers.

PPS. I left v5.23 up, in case people don't feel like dealing with an experimental (HEX) function implementation

PPPS. The HEXing is not err... "real"? hexing at the moment, so I'll upgrade the algorithm later... still works for storage purposes though
_________________
Real arrays are here.
Customizable self-updaters are too.
Back to top
View user's profile Send private message
Elevator_Hazard



Joined: 28 Oct 2006
Posts: 303
Location: Illinois

PostPosted: Sun Apr 01, 2007 7:01 pm    Post subject: Reply with quote

don't forget to change your post on AHKUpdater about the hex =P
_________________
Changed siggy at request of ahklerner Very Happy
Back to top
View user's profile Send private message
olegbl



Joined: 13 Dec 2006
Posts: 19

PostPosted: Sun Apr 01, 2007 9:17 pm    Post subject: Reply with quote

I didn't have much time to work on it yet, so it's still "alpha/beta/whatever" state... I'll get to adding HEX, fixing up any bugs, and adding a bunch of functions to AUF files when I get some time...
(so much work this past week and this weekend =/ ) ...
Thanks for the reminder!
_________________
Real arrays are here.
Customizable self-updaters are too.
Back to top
View user's profile Send private message
Darkangael
Guest





PostPosted: Sun Jun 17, 2007 1:55 pm    Post subject: Reply with quote

Hi There. Great script, however I noticed that the AHKAConvert function as follows:

Code:

   AHKAConvert(Var)
   {
      global
      local Length := %Var%0
      local Array := AHKANewArray()
      Loop, %Length%
      {
         local TempVar := %Var%%A_Index%
         local Array  := AHKAAdd(Array,TempVar)
      }
      return Array
   }

Doesn't work for me. I am converting the result of
Code:
WinGet, var_name, List, "A Title"

using
Code:
ArrayName := AHKAConvert("var_name")


The problem appears to be the line
Code:
local Length := %Var%0

As I understand it, the size of an array is stored in %Var% not %Var%0. My results from removing the 0 from the end of this line seem to indicate that this is correct as the convert function now works. [/code]
Back to top
olegbl



Joined: 13 Dec 2006
Posts: 19

PostPosted: Sun Jun 17, 2007 8:54 pm    Post subject: Reply with quote

Thank you for your report. The problem lies in the fact that different functions of AHK generate different "generic" arrays.
For example:
StringSplit generates an array which stores its length in arr0
WinGet generates an array which stores its length in arr
I've attempted to create a simple fix using the following:
Code:
AHKAConvert(Var)
{
   global
   local Length := %Var%
   if Length =
      local Length := %Var%0
   local Array := AHKANewArray()
   Loop, %Length%
   {
      local TempVar := %Var%%A_Index%
      local Array  := AHKAAdd(Array,TempVar)
   }
   return Array
}

I've tested it with an empty WinGet, and a full+empty StringSplit
Tell me if it works, because I'm not very familiar with WinGet, and pathetically enough can't make it generate a full array for me (just a size 0 one)

You can either update ur AHKArray by copying the code from here, or simply download the updated version from first page

Thank you for your report
_________________
Real arrays are here.
Customizable self-updaters are too.
Back to top
View user's profile Send private message
Darkangael
Guest





PostPosted: Mon Jun 18, 2007 10:38 am    Post subject: Reply with quote

That worked. I suspected as much about different functions producing different kinds of array. Hopefully one day this will be fixed (or the rumored AHKv2.0 with proper arrays is released).
Back to top
philz



Joined: 05 Jun 2007
Posts: 76
Location: USA

PostPosted: Mon Jul 09, 2007 7:18 pm    Post subject: Reply with quote

Olegbi wrote:
Code:
AHKAFloor(number)
   {
      if number=0
         return 0
      newnumber := 0
      if number<0
      {
         Loop
         {
            if newnumber>%number%
               newnumber--
            else
               return newnumber
         }
      }
      if number>0
      {
         Loop
         {
            if newnumber<%number%
               newnumber++
            else
               return --newnumber
         }
      }
   }


you said that this function is slow
would this be any faster
Code:

fastfloor(number) {
   if number = 0
      return, 0
   if number = % floor(number)
   {
      if number > 0
         return, number + 1
      else return, number - 1
   }
   else return, floor(number)
}


it seemed to me after checking your source code that you wanted to return an integer that fulfilled the following.

abs(floor(number)) > abs(floor(returnvalue)
which is what mine does.

i am uncertain that fastfloor is actually faster than ahkfloor but less lines will definately be executed in fastfloor for most numbers

just a thought.
Back to top
View user's profile Send private message Send e-mail AIM Address
Guest






PostPosted: Mon Nov 26, 2007 6:12 pm    Post subject: Reply with quote

How about

AHKAString(Array,Delimiter="")
{
Output := ""
Length := AHKASize(Array)
Loop, %Length%
{
Output := Output . AHKAGet(Array,A_Index) . Delimiter
}
return Output
}
Back to top
Ahkarray
Guest





PostPosted: Tue Dec 11, 2007 6:33 pm    Post subject: Reply with quote

To olegbl

About the AHKAHEX function, It's the only one that reall work for the strings with `n,`r, Asian characters.

Thanks for the script.
Back to top
olegbl



Joined: 13 Dec 2006
Posts: 19

PostPosted: Wed Dec 12, 2007 12:40 am    Post subject: Reply with quote

Er, I believe (it was a while ago, bad memory XD), that I simply used ascii to transform it to hex, so, as long as the char is within the first 255 (not counting 0, or 256 counting 0) ASCII characters it should be hexified. After that, er, can't really be hexed anyway, but it would probably give some weird results, maybe like characters that would through ASCII add up to the one that one wants....
Anyway, welcome for the script, glad it's of some use =)
_________________
Real arrays are here.
Customizable self-updaters are too.
Back to top
View user's profile Send private message
suitedtens



Joined: 28 Apr 2008
Posts: 4

PostPosted: Mon Apr 28, 2008 10:16 pm    Post subject: Reply with quote

Hi,

Great script!!! I'm pretty new to AHK and already the built-in fake "array" stuff was annoying me. Smile

I registered to post about two weird things I have noticed, one looks to be a straightforward bug and the other I have no idea.

First -
There appears to be a small bug in AHKAGet. The code

Code:

if Index2!=
{
   if AHKAIsArray(Array)
   {
       Array := AHKAGet(Array,Index2)
   }
}
else
{
   return Array
}


is repeated twice, the effect of which is that the 3rd subscript passed to this function does nothing (probably messes up later subscripts as well). Removing the duplicate block makes things work as expected (wheee, multi-dimensional arrays!).

Second -
The AHKAConvert function is behaving strangely for me. Namely, it looks like the variable I pass isn't accessible inside the function. Example:

Code:

strtest=1_2_3_4_5
StringSplit nativearr, strtest, _
newarr := AHKAConvert("nativearr")


I get nothing back in newarr (or more specifically, "[]") and if I put a MsgBox call inside AHKAConvert to spit out nativearr1 (for example) I also get nothing. Very strange. I worked around it for now using

Code:

newarr := AHKANewArray(){
Loop %nativearr0%
   newarr := AHKAAdd(newarr, nativearr%A_index%)
Back to top
View user's profile Send private message
olegbl



Joined: 13 Dec 2006
Posts: 19

PostPosted: Mon Apr 28, 2008 11:47 pm    Post subject: Reply with quote

Thank you for the reports.
For the first one, the problem is fixed (typo on my part (ctrl-v)): I'll upload the new version it as soon as I can...
For the second one, the reason is that something is assigned to Var.
Example (As Was In Documentation - Will Change):
Code:

Random := "I am a jolly man"
StringSplit, Random, Random, %A_Space%
Array := AHKAConvert("Random")

Will produce "[]", but
Code:

Random := "I am a jolly man"
StringSplit, Random2, Random, %A_Space%
Array := AHKAConvert("Random2")

Will work.
AHKAConvert first checks "Random" for length, then "Random0", since AHK isn't consistent about the way it returns fake arrays, some have length as "name0", some have it as "name". So, in the "name0" case, make sure "name" doesn't have a value.
I had it wrong in the documentation, but the function is fine.
So, I'll update the docs, hopefully this explains the problem.
_________________
Real arrays are here.
Customizable self-updaters are too.
Back to top
View user's profile Send private message
suitedtens



Joined: 28 Apr 2008
Posts: 4

PostPosted: Fri May 02, 2008 5:57 am    Post subject: Reply with quote

Cool, that worked - thanks!

Next question. Smile

How do you do a set of a particular element in a 3-dimensional array? There's no overload for AHKASet like there is for AHKAGet to accomodate multi-dimensional arrays, but I thought I might be able to do something like this:

Code:

TestAHKASet3Dim(array, value, index1, index2, index3)
{
    dim2 := AHKAGet(array, index1)
    dim3 := AHKAGet(dim2, index2)
    dim3 := AHKASet(dim3, value, index3)
    dim2 := AHKASet(dim2, dim3, index2)
    array := AHKASet(array, dim2, index1)
    return array
}


...but I'm seeing some odd behavior after the first set of an array element to a sub-array (this line dim2 := AHKASet(dim2, dim3, index2)).

In a test I have dim2 equal to [[256,2],[100],[2],[4],[]].
I am trying to set the first sub-sub-element to 500 so the result should be [[500,2],[100],[2],[4],[]].
Instead I get [[500,2],[256,2],[100],[2],[4]].

It's like it is inserting the subarray instead of replacing the element I'm telling it to replace.

Is there some other way to do this or is my code messed up? Laughing

Thanks!
Back to top
View user's profile Send private message
olegbl



Joined: 13 Dec 2006
Posts: 19

PostPosted: Fri May 02, 2008 7:31 am    Post subject: Reply with quote

Thank you for the report.
Turns out, the remove function was "broken" for removing nested arrays.
Fixed it, and upgraded it in the process. Now your method will work.
However, it is no longer necessary, I overloaded the add function.
You can now use it to set values up to the 10th dimension.
Ex:
Code:

Arr := AHKASet(Arr, "NewValue", 5, 2, 9, 1, 4)
; Arr[5][2][9][1][4] = "NewValue";

New version (5.41) is available for download.
Also, I've updated the docs to match the capability.

Also, here's my test file in case there's something I might have missed in testing...
Code:

#MaxThreadsPerHotkey 1
#MaxThreads 1
#SingleInstance force

Test:
   ; Create New 3-Dimensional Array :: [A, B, [C1, C2], D, [E1, [E2i, E2ii, E2iii], E3], F]
      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")
   
   ; Lets Change The "D" to a "D+"
      myarr := AHKASet(myarr, "D+", 4)
      result := AHKAGet(myarr, 4)
      MsgBox, %result%
   
   ; Lets Change The "C1" to a "C1+"
      myarr := AHKASet(myarr, "C1+", 3, 1)
      result := AHKAGet(myarr, 3, 1)
      MsgBox, %result%
return

#Include AHKArray.ahk

_________________
Real arrays are here.
Customizable self-updaters are too.
Back to top
View user's profile Send private message
suitedtens



Joined: 28 Apr 2008
Posts: 4

PostPosted: Fri May 02, 2008 6:34 pm    Post subject: Reply with quote

Works perfectly for my 3-d cases. I appreciate the speedy fix very much!!!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group