AutoHotkey Community

It is currently May 27th, 2012, 9:21 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: December 28th, 2011, 2:00 am 
Offline

Joined: October 2nd, 2008, 8:16 pm
Posts: 21
Hello Everybody,

I haven't been on here in quite some time now, so I don't really know what all is changed in the language. I have quite a few scripts that I've grandfathered & still use today in AutoHotKey, but I've found the language to be kind of immature when it comes to dealing with masses of data. Maybe it's my lack of creativity, but there seems to be no intuitive way to create user defined types. That's a bit of a problem, let me explain why.

Lets say I have this large set of datum that I need to store and index. Take a CSV database for example. I want to create a data structure that uses key->value pairing and stores those pairs in a tree. If you know Java, you'll know that this data structure is conveniently noted as a TreeMap.

Is there a way to do this in AHK and I'm just not realizing it?

Thanks,
-- elektron


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2011, 2:12 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
In AutoHotkey_L you have two data types: strings ("text", numbers like 9, floats like 9.7) and Objects. Objects use key→value pairings, and can be nested in other objects. That's the closest you'll get.

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2011, 2:20 am 
Offline

Joined: October 2nd, 2008, 8:16 pm
Posts: 21
Is there a way to create something as primitive as a Linked List? I'd prefer the dynamic memory solution than the one using an array of objects.

Thanks,
-- elektron


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2011, 2:27 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
elektron wrote:
Is there a way to create something as primitive as a Linked List?
Realize that AutoHotkey is for non-programmers primarily. Most automation tasks do just fine without a linked list. If AHK isn't adequate, you're best off in a more well-known language such as C(++|#), Java etc. I suppose if you don't want to use objects, your last resort would be defining your own data structure with NumPut and friends

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2011, 2:39 am 
Offline

Joined: October 2nd, 2008, 8:16 pm
Posts: 21
nimda wrote:
elektron wrote:
Is there a way to create something as primitive as a Linked List?
Realize that AutoHotkey is for non-programmers primarily. Most automation tasks do just fine without a linked list. If AHK isn't adequate, you're best off in a more well-known language such as C(++|#), Java etc. I suppose if you don't want to use objects, your last resort would be defining your own data structure with NumPut and friends


Nimda,

Firstly, I just wanted to say thank you for all your help. It's rare to find someone as resourceful and open with their time as you are. I most certainly appreciate it.

Secondly: while I realize that AHK is mostly for non-programmers, the version of AHK that I am familiar with was the one that I've been using since I signed up for these forums. That subset of the language was much simpler than the one I've just been made aware of. I guess that's what I get for not keeping up with the growth!!!

I've got to look into this new subset of the language. It seems to be awfully interesting. That NumPut procedure I saw looks like an awful lot of fun. I get to tinker with memory addresses, oh boy :-).

Take Care,
-- elektron


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2011, 9:48 am 
Offline

Joined: June 4th, 2010, 9:04 pm
Posts: 1347
Location: california
here's a simple example of a circular forward linked list you could have it link in both directions. This was created using AHK Basic v1.0.48.05
Code:
; simple linked list example (circular)
Item1 = 99,4 ; 1 points to item 4
Item2 = 55,3 ; 2 points to 3
Item3 = 22,1 ; 3 points to 1
item4 = 66,2 ; 4 points 2

; pick a start point in the list
random x, 1,4
; walk the list
loop
{
   while (!getkeystate("MButton"))
   {
      y := Item%x%
      msgbox,,,Item%x% = %y%
      stringsplit, z, y, `,
      x = %z2%
   }   
}
ExitApp

I purposely altered the links so they were out of sequence so you could see it wasn't just iterating down the list of item numbers.
http://en.wikipedia.org/wiki/Linked_list

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2011, 3:16 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
elektron wrote:
Is there a way to create something as primitive as a Linked List? I'd prefer the dynamic memory solution than the one using an array of objects.
If performance is your concern, try not to make any assumptions based on your experience in other languages. Something that worked in Java mightn't work as well in AutoHotkey, especially if you're comparing built-in data structures to scripted ones. Also, an "array of objects" in Java isn't quite the same thing as an "array of objects" in AutoHotkey_L.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2011, 6:52 pm 
Offline

Joined: October 2nd, 2008, 8:16 pm
Posts: 21
Lexikos wrote:
elektron wrote:
Is there a way to create something as primitive as a Linked List? I'd prefer the dynamic memory solution than the one using an array of objects.
If performance is your concern, try not to make any assumptions based on your experience in other languages. Something that worked in Java mightn't work as well in AutoHotkey, especially if you're comparing built-in data structures to scripted ones. Also, an "array of objects" in Java isn't quite the same thing as an "array of objects" in AutoHotkey_L.



I'm less concerned with the performance of the language and more concerned with the performance of the data structure. I want to index and search in O(log2(n)) rather than O(n). However, I don't know the maximum size of the data structure, so I can't use a heap or an array base implementation of the data structure. I'd rather just have a simple binary search tree. Easy coding, or at least it should be, anyways

I'm not trying to make any assumptions, I just want to know the synalogous data structure in AHK. I was thinking more high-level and was hoping that any one of you can help me with that.

I was thinking all night about how to do this... still haven't came up with an elegant solution.

Thanks,
-- elektron


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2011, 10:59 pm 
Offline

Joined: June 4th, 2010, 9:04 pm
Posts: 1347
Location: california
Electron wrote
Quote:
I'm less concerned with the performance of the language and more concerned with the performance of the data structure.

If you remember several critical pieces of information the job will make a lot more sense to you
    1. Autohotkey is an interpreted language. That means the performance of the language and the performance of the data structure are inextricably tied together.
    2. The fact that there are design-based limits on what data primitives AutoHotkey provides makes creating any specific data structiure outside that subset a bit more work than would be required in a different language.
    3. That AutoHotkey was primarily designed for program automation tasks and not data manipulation makes it a bit less suitable for data mining activities than a more general purpose programming language would be.

Each computer language is inherently designed to solve a given problem in computer science. If you try to push the language out of that "comfort zone" you will find that your programming solutions get more involved and less efficient than they would be if they were constrained within that original problem space.

It should also be noted that AutoHotkey can be "bolted on" to a more data oriented language through the use of AutoHotkey.Dll to provide services that AutoHotkey excels at to supplement the base language's feature set. That may be more in line with what you have in mind for your solution.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2011, 3:22 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
You could take a look at this thread for an example of a search-optimized data structure in AHK-L.

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2011, 3:41 am 
Offline

Joined: October 2nd, 2008, 8:16 pm
Posts: 21
[VxE] wrote:
You could take a look at this thread for an example of a search-optimized data structure in AHK-L.


Lovely. This is exactly what I was looking for. Thanks. I'll review the source code sometime tomorrow. :-)

Also, while I'm on the subject. Is there a particular way that I can see the C++ or ASM code generated by the AHK interpreter/compiler (I don't know which it really does, semantically).

Thanks,
-- elektron


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2011, 4:06 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
AHK doesn't actually compile scripts (AHK is an interpreted language, remember?). You can look at the source (it's available on the main downloads page).

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2011, 4:07 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
It's interpreted, therefore there is never any C++ or ASM code.

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2011, 4:27 am 
Offline

Joined: October 2nd, 2008, 8:16 pm
Posts: 21
Thanks :-)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google Feedfetcher, JSLover, migz99, Yahoo [Bot] and 68 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