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 6]
Goto page 1, 2, 3, 4, 5  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: 27

PostPosted: Wed Dec 13, 2006 7:26 am    Post subject: AHKArray [Real Array - One Variable] [Version 6] Reply with quote

Downloads
Latest Version : 6.00 (Build 2008:0730:1530)
Warning! Version 6.00 is NOT compatible with previous versions!
Quote:
Download (v6.00) @ Location 1 : AHKA AHK File
Download (v5.42) @ Location 1 : AHKArray AHK File
Download (v5.41) @ Location 1 : AHKArray AHK File
Download (v5.39) @ Location 1 : AHKArray AHK File
Download (v5.38) @ Location 1 : AHKArray AHK File
Download (v5.37) @ Location 1 : AHKArray AHK File
Download (v5.23) @ Location 1 : AHKArray AHK File


Bug Reports & License
Please send all bug reports, comments, suggestions, etc to olegbl@gmail.com, or post them as replies to this forum topic.
PS. Feel free to edit/use code as you like, the license just says that you're allowed to do anything you like, as long as the license stays there, and my name doesn't get used for advertising (yeah right XD).

Description
AHKA stands for AutoHotkey Array (or AHKArray).
AHKArray provides a way to store multiple variables, as one. It eliminates the necessity for using global variable arrays that are generated by functions such a stringsplit.
This means arrays can now be stored in ONE varaible, and returned by a function. No more array variable clutter.
AHKArray supports an "infinite" amount of dimensions. (Well, as much as your memory can take without blowing up.)
Starting with v5.35, contents of Array are HEXed, enabling the use of ANY of the first 256 ASCII characters inside of them.
This library is rather heavy and feature filled. If you want a smaller, faster single variable array library, please refer to infogulch's SimpleArray.

Specifics
~ Syntax : For Non-HEXed AHKArray is similar to ActionScript
Code:
Array := "[a,b,[A,B],c]"

~ Syntax : For HEXed AHKArray is similar to a HEXed ActionScript
Code:
Array := "[61,62,[97,98],63]"
Array := AHKA_NewArray("[a,b,[A,B],c]")

~ Compatability : Conversion from standard Array%i% arrays, is inbuilt
~ Advanced Indexes :
    Index=0 : (DEFAULT) Add/Get/Remove/Set/Etc the LAST index in the array
    Code:
    AHKA_Add("[1,2,3]",BLAH) ;returns "[1,2,3,BLAH]" ;same as AHKA_Add("[1,2,3]",BLAH,0)

    Index>0 : Add/Get/Remove/Set/Etc the INDEX index in the array
    Code:
    AHKA_Add("[1,2,3]",BLAH,2) ;returns "[1,BLAH,2,3]"

    Index<0 : Skip INDEX indexes from back and then Add/Get/Remove/Set/Etc the next index
    Code:
    AHKA_Add("[1,2,3]",BLAH,-1) ;returns "[1,2,BLAH,3]"

~ Usage : Simply put the "AHKA.ahk" file into your "AutoHotkey/Lib/" directory, OR include it at the end of your program via "#Include AHKA.ahk".
~ HEX : The data stored can now be HEXed automatically
~ Chaining : All functions are chainable :
Code:
Array := AHKA_Remove(AHKA_Set(AHKA_Add(AHKA_Add(AHKA_Add(AHKA_NewArray(),"A"),"B"),"C"),"B+",2),1)
; [] -> [A] -> [A,B] -> [A,B,C] -> [A,B+,C] -> [B+,C]
~ Free-Style Decalaration (Automatic HEXing) :
Code:
myArray := AHKA_NewArray("[1,2,[31,32],4]")

Don't see a feature you want? Post it here, and I'll try to add it.

Reserved Strings for Non-HEXing
Inside AHKArray, you may not store strings containing the following symbols ONLY IF you are NOT using HEXing:
Code:
[
]
|
,

Note: Contents are automatically HEXed. This can be changed by calling AHKA_SetDebug(true) to disable HEXing, and AHKA_SetDebug(false) to enable HEXing.

Version History
Quote:

Version 0
First release
Basic functions work
Dimensions work up to 2D (in most cases)
Version 1 - 3
Fixed a bug with adding to an empty array.
Added Insert function
Added a "Documentation"
Added a Convert function (now, all the functions that generate Array%i% kind of arrays, can also be used with AHKAArray (the generated variable Array%i% must be global!)
Changed array format
It is now possible to say this:
Code:
Array = "{1,2,3,4}"
To declare an array
Fixed an error with Get()
Version 4
Completely rewrote scripts (thus fixing lots of bugs)
All basic functions work (as tested) for as many dimensions as needed
Array Syntax changed to Flash-Style
Code:
Array = "[1,2,[31,32,[331,332],34],4,5]"

Added Split() function
Version 5
Initial:
Completely rewrote scripts from scratch ... again
All functions work (as tested) for as many dimensions as needed
Sample code included
Array dimensionality is now supported by Parse/Unparse functions (wrongly named so =P)
Patched:
Added Sort() function
Added Swap() function
Added Minimum() function
Added Maximum() function
Added Find() function
Added Reverse() function
Added Merge() function
Added Trim() function
Added Mathematical Floor(),Abs() functions
Upgraded Get() function
Added String() function
Added HEX support
Get() and Set() functions Overloaded
Set() function speed improved
Fixed Remove() function for arrays
Version 6
Overloaded every major function.
Added freestyle array declaration to NewArray.
Changed to Library format, #include not necessary anymore.
Optimized various functions.
Added "debug mode" (dynamic non-HEXing mode).
Made a new Documentation.
Created (still creating) complete AHKA tester (with GUI), usable as sample code.


Documentation
Documentation & Tutorials for AHKA are availiable here.
Note: Utility functions are not yet documented, but are also not meant to be used on their own (only by other functions), so no functionality is lost.
Note: Tutorials are still under construction, sorry.
_________________
Real arrays are here: AHKArray Version 6!


Last edited by olegbl on Mon Aug 25, 2008 8:37 am; edited 53 times in total
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Wed Dec 13, 2006 8:17 am    Post subject: Reply with quote

Since there are still several commands and functions that will only output to a regular array, how about a function that converts a regular array to an AHKArray? It would be a lot easier to use then, instead of having to do something like this:

Code:
NewArray := AHKANewArray()
Loop %Array0%
   AHKAAdd(NewArray,Array%A_Index%)


Edit: Did you add that while I wasn't looking? Laughing

Any plans for hash tables, stacks, queues, trees? Smile
Back to top
View user's profile Send private message
olegbl



Joined: 13 Dec 2006
Posts: 27

PostPosted: Wed Dec 13, 2006 9:40 pm    Post subject: Reply with quote

Yup, added it behind your back Razz
I'm currently upgrading the whole script, and slightly changing the format, to make it a lot easier to use, etc...
Will post V3 soon.

Edit: Done

Edit2: Oh, didn't see the question, looked like signature XD
Well, for now, this is pretty much as far as I'm going, though, later on I will probably add everything from full character storing compatibility, to auto-sorting, and byte-storage
(the whole reason I did this, is because I'm making a code-wise self updater (i already made like 3, but they suck), and I need local variable arrays for it, (to make it much more efficient, and not global)

Edit3: Er, I've decided against taking this to an actual array level, that can be done in AHKv2 or whatever it is thats being talked about, but for now, I think this is plenty good enough to have...
If anyone wants to do it though, haha, go ahead =P
Back to top
View user's profile Send private message
Mistrel



Joined: 12 Sep 2005
Posts: 188

PostPosted: Wed Jan 10, 2007 5:55 am    Post subject: Reply with quote

I have some unfinished functions I wrote for another AHK project that might be useful to you. It has "remove from queue" and "remove from stack" support for standard AHK (fake) arrays. There are also some other array functions like PrintArray and CollapseArray.

http://www.autohotkey.com/forum/viewtopic.php?t=13885&highlight=another+method
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Mar 04, 2007 3:42 am    Post subject: Reply with quote

is any1 reading this if so i have this problem this code produces a msgbox with zero on it what am i doing wrong
Code:
charArray := AHKANewArray()
Loop,5
   AHKAAdd(charArray,65)
var := AHKASize(charArray)
MsgBox %var%

Thanks
Back to top
pantagruel



Joined: 08 Oct 2006
Posts: 67
Location: denmark

PostPosted: Sun Mar 04, 2007 7:06 pm    Post subject: invalid array format Reply with quote

hi,

It seems no matter what I do I get back an invalid array format error, here are the various ways I have tried to declare an array:

xarray = [1, 2, 3]

xarray = "[1,2,3]"

xarray := "[1,2,3]"

xarray := "{1,2,3}"

xarray = "{1,2,3}"

xarray := AHKANewArray()

xarray := AHKAAdd(xarray,1)

after which I try to do the following



xindex = 1



xindex := 1

either one I don't care

finally


#r::
xvalue := AHKAGet(xarray,1)

return

which tells me that I have an invalid array format.

thank you
Back to top
View user's profile Send private message
Guest






PostPosted: Mon Mar 05, 2007 12:31 am    Post subject: Reply with quote

Yeah im having the same problem i posted my code before and it seems im doing it right but the array never initializes and i always get array format errors
Back to top
pantagruel



Joined: 08 Oct 2006
Posts: 67
Location: denmark

PostPosted: Tue Mar 06, 2007 10:28 am    Post subject: version problems I suppose Reply with quote

I'm going to suppose that the culprit is the version of Autohotkey used. I'm using 1.0.46.09, anyway I figure that, given the multitudinous variations I've done that it is not going to work.
Back to top
View user's profile Send private message
olegbl



Joined: 13 Dec 2006
Posts: 27

PostPosted: Wed Mar 14, 2007 5:24 am    Post subject: Reply with quote

Err, sorry for a rather long non-reply.
Was busy, didn't do AHK.
Right now, I'm writing a much better, more efficient version of AHKArray (from scratch).
As for the questions, I'll try to answer (though late):
Re-Guest:
when you use functions, you gotta set your array to equal them...
Code:
charArray := AHKANewArray()
Loop,5
   AHKAAdd(charArray,65)
var := AHKASize(charArray)
MsgBox %var%
doesn't work, but
Code:
charArray := AHKANewArray()
Loop,5
  charArray := AHKAAdd(charArray,65)
var := AHKASize(charArray)
MsgBox %var%
should work.

Re-Pantagruel:
Code:
xarray := "[1,2,3]"

should work.
Code:

xvalue := AHKAGet(xarray,1)
MsgBox, %xvalue%

should work too.

However, if they don't, maybe it is because of AHK version like was mentioned...
Well, I'm working on AHKArray v5 (im using the newest AHK version to do so)... So, I'll get it done in a few days.
(Hopefully including some code examples =P)

PS Don't forget the #include AHKArray.ahk at the end of your prog.

==EDIT==
Worked until midnight, but here's V5... hopefully should work for pretty much everything... didn't do TOO much testing yet..
Back to top
View user's profile Send private message
guest1
Guest





PostPosted: Sat Mar 31, 2007 4:47 pm    Post subject: Reply with quote

great! and perfect!!

also really impressive documentation!!!
Back to top
olegbl



Joined: 13 Dec 2006
Posts: 27

PostPosted: Sat Mar 31, 2007 11:13 pm    Post subject: Reply with quote

Thanks!

Next version will be out sometime soon.
(I think there's 3 new methods, maybe more)
(Not this weekend though, too busy...)
_________________
Real arrays are here: AHKArray Version 6!
Back to top
View user's profile Send private message
Elevator_Hazard



Joined: 28 Oct 2006
Posts: 304
Location: US

PostPosted: Sun Apr 01, 2007 2:25 am    Post subject: Reply with quote

So you can't use certain characters? how about converting to hex so that all letters can be used, and you can use many more delimiters. Of course the size of it will be multiplied by 2...
_________________
Changed siggy at request of ahklerner Very Happy
Back to top
View user's profile Send private message
olegbl



Joined: 13 Dec 2006
Posts: 27

PostPosted: Sun Apr 01, 2007 4:05 am    Post subject: Reply with quote

Well, I was thinking of instead putting 4 optional parameters at the end of each function specifying delimeters, so they could be customized.
However, I do like the HEX idea, thanks!
Might implement that in the next version.
_________________
Real arrays are here: AHKArray Version 6!
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

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

Maybe have a initialize function to change the characters. Then it only needs to be set once.

How do I get values from a mutiple dim array? I have to call AHKAGet multiple times, right? Could there be a function that gets the value by, e.g.
AHKAValue(MyArray, IndexDim1, IndexDim2, IndexDim3, etc. up to IndexDim10)?
By making the indicies optional and limited to 10 dims it should be possible.

Is there an option to sort numerically?

Just my two cents.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
olegbl



Joined: 13 Dec 2006
Posts: 27

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

Well, to make an init function, the variables would have to be global, which is what I've been trying to avoid...
I did however already implement HEX... This removes the ability to say
Code:
Array :="[a,b,c]"
;Instead, you must now say
Array := "[61,62,63]"

And it also limits the storage capacity to the first 255 ascii chars, but it does remove the limitation for dilimeter characters.
I added an easy way to enable/disable HEXing, which requires a simple change of "false" to "true" in two places.

To get a value from multiple dimension you could say:
Val := AHKAGet(AHKAGet(AHKAGet(Array,X),Y),Z)
But, it would be rather easy to implement the multiple index thing, so I'll try to do it.

Numerical sorting, I think is the same in AHK, so the sort method should do that. (it basically compares values to each other using the > and < symbols which work both ways as far as I know)

Thanks for you suggestions!

I'll try to get all this stuff implemented and released in the next version...
_________________
Real arrays are here: AHKArray Version 6!
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 1, 2, 3, 4, 5  Next
Page 1 of 5

 
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