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 

[lib] SimpleArray - short & fast string array - v3.5
Goto page Previous  1, 2, 3, 4, 5
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
infogulch



Joined: 27 Mar 2008
Posts: 378

PostPosted: Thu Feb 05, 2009 7:22 am    Post subject: Reply with quote

Ah, bmcclure, you're using the named indexes wrong. Note the syntax on the front page:
SA_Set( Array, Val, [nIdx="+1", Insert=false, giveName=""] )

The nIdx params are only for referencing a name, not creating one. I wanted to avoid some issues when I set that up, but maybe it's not worth the trouble.
_________________

Scripts
- License
Back to top
View user's profile Send private message
bmcclure



Joined: 24 Nov 2007
Posts: 766

PostPosted: Thu Feb 05, 2009 10:59 am    Post subject: Reply with quote

Ah, thanks for that! Fixing it in my code, and will report back if I have further trouble.
_________________
Ben

My Trac projects
My Wiki
[Broken] - My music
Back to top
View user's profile Send private message
colek42



Joined: 31 May 2009
Posts: 12

PostPosted: Mon Jun 01, 2009 4:51 am    Post subject: Problems with 3D arrays Reply with quote

Having some trouble with creating a 3D array.

I have a list of files with data associated with them


Code:

[file1 | iso | input_string | name | output_dir | source ]
[file2 | iso | input_string | name | output_dir | source ]
[file3 | vts | input_string | name | output_dir | source ]
[file4 | vts | input_string | name | output_dir | source ]


Without documentation or examples it is going to be difficult for me to code this. Would appreciate some help.

Excuse my ignorance and thanks for your help!
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 378

PostPosted: Wed Jun 03, 2009 7:23 pm    Post subject: Reply with quote

I haven't worked on SimpleArray for a while now, so those of you following this may be happy to know that I'm working on it again. I'll be adding some new functions (sort, swap, join, find, and convert from psuedo array and convert from delimited string, + others) along with restructuring functions (e.g. changing functions to be recursive) and adding better documentation and examples.

By the way, if you have any ideas for new functions/different functionality, now would be the time to ask for it. Very Happy

I'm hoping to be done with it by the end of this weekend, but I wouldn't be holding my breath if I were you. Wink

Thanks!
_________________

Scripts
- License
Back to top
View user's profile Send private message
hugov



Joined: 27 May 2007
Posts: 2473

PostPosted: Wed Jun 03, 2009 9:00 pm    Post subject: Reply with quote

Support ++

* Replace items X with Y in Array

Example, replace 1 with 5
before: 1-2-3-4-1-2
after: 5-2-3-4-5-2

* Remove duplicate entries in Array without affection order (e.g. not a Sort Unique)

Example, keep first occurance of 1 2 7 8 remove subsequent ones
before: 8-7-5-4-1-2-6-7-1-2-8-a
after: 8-7-5-4-1-6-a

Can't wait Wink
_________________
Tut 4 Newbies
TF : Text file & string lib, TF Forum
Back to top
View user's profile Send private message Visit poster's website
infogulch



Joined: 27 Mar 2008
Posts: 378

PostPosted: Tue Jun 09, 2009 12:10 am    Post subject: Reply with quote

Hi guys. Sorry I couldn't push the update yet, I was gone pretty much all weekend long. To make up for it, I'll give a partial release. Hope you guys like it. Very Happy

SimpleArray v3.1

Find information about the update, including new and changed features and ToDo inside. Some functions already have their documentation in them.

I haven't tested it throughly yet, so there may still be bugs. I'm not releasing this on the first post because I hope to update it by the end of this week.

Thanks!

Edit:
Oops, these should be added to the ToDo: Create Unique, Create Replace
(thanks for the suggestions Very Happy )
_________________

Scripts
- License
Back to top
View user's profile Send private message
hugov



Joined: 27 May 2007
Posts: 2473

PostPosted: Thu Jun 11, 2009 12:49 pm    Post subject: Reply with quote

Quick test report 3.1:

New SA_Get, SA_Del, SA_Set seem to work OK for me

Tested:

SA_ConvertDelimited: OK
SA_Find: OK
SA_FindCnt: OK
SA_Join: OK
SA_ConvertPsuedo: Example would be appreciated
_________________
Tut 4 Newbies
TF : Text file & string lib, TF Forum
Back to top
View user's profile Send private message Visit poster's website
infogulch



Joined: 27 Mar 2008
Posts: 378

PostPosted: Thu Jun 11, 2009 3:27 pm    Post subject: Reply with quote

HugoV wrote:
SA_ConvertPsuedo: Example would be appreciated
OK, I guess i owe you guys some examples. Razz
Code:
files0 := 0
Loop C\*.*
    files%A_Index% := A_LoopFileFullPath, files0++
SimpleArrayFiles := SA_ConvertPsuedo("files", files0)
Code:
A_0 = %0%
cliArgs := SA_ConvertPsuedo("", A_0)
Can you guess what this does?

Note that this works only on global psuedo arrays. It cannot convert psuedo arrays created local in functions. Also, the SetFormat mode for integers must be decimal for expected results.

Note that SA_Find currently only finds a partial match, but the new version will give you the option for matching part of an element or the entire element. SA_Find also doesn't compare numbers numerically, but as a string, so if you search for "2" and an element has "02" it won't match. (This is for the whole match option) I may add another find function that compares each element, but it will be slower.

A quick example of SA_ConvertDelimited for two dimensions.
Code:
arr := SA_ConvertDelimited("a,b,c|1,2,3|?,*,@|Z,Y,X,W", "|,")

SA_ConvertPsuedo can also accept multiple dimensions, but I can't think of a practical example atm, so here's something i just made up:
Code:
a1_1 := "abc"
a1_2 := "klmno"
a1_3 := "vwx"
a2_1 := "def"
a2_2 := "pqr"
a2_3 := "yz1"
a3_1 := "hij"
a3_2 := "stu"
a3_3 := "234"

arr := SA_ConvertPsuedo("a", "3,3", "_")


While SA_ConvertDelimited works for arrays where the other dimensions are different sizes, SA_ConvertPsuedo doesn't. To get all of the elements of a psuedo array, pass the maximum number of elements that each dimension has. (i.e. if arr1_* has 5 elements and arr2_* has 7 elements, pass "2,7" for the SA_Dims param. Note that there will be two blank elements at the end in the first dimension's first element.)

Very Happy
_________________

Scripts
- License
Back to top
View user's profile Send private message
hugov



Joined: 27 May 2007
Posts: 2473

PostPosted: Thu Jun 11, 2009 7:19 pm    Post subject: Reply with quote

Thanks for examples, in my first test ConvertPsuedo "failed" because
I passed it as list and not "list" Embarassed
Code:
list=a|b|c|d|e
stringsplit, list, list, |
array:= SA_ConvertPsuedo("list",5)
; array = 1-2-3-4-5 --- oops that is a-b-c-d-e of course


Edit:

Re: cliArgs, yes it stores the command line parameters passed on to the script in the array, nice Wink
_________________
Tut 4 Newbies
TF : Text file & string lib, TF Forum
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Wed Aug 19, 2009 10:48 am    Post subject: Reply with quote

can someone demonstrate how to make a simple 2D array? like this?

Seat|Chips
_______________
Index1: 8 | 1500
Index2: 9 | 3000
Index3: 1 | 1500
Index4: 3 | 1500
Index5: 7 | 1500

thanks
Back to top
infogulch



Joined: 27 Mar 2008
Posts: 378

PostPosted: Wed Aug 19, 2009 3:57 pm    Post subject: Reply with quote

Guest: may I first suggest that you make an account? It will only take a moment, and then I'll know for sure that I helped you out, and you'll know when there are updates to this and other threads you post in. Smile

To answer your question, there are many ways you could set this up.

To do exactly what you're asking for you could use one of these methods:
Make a delimited list and use SA_ConvertDelimited:
Code:
array := SA_ConvertDelimited("8,1500|9,3000|1,1500|3,1500|7,1500", "|,")

Push it manually:
Code:
array := SA_Set(array, SA_Set(SA_Set("", 8), 1500))
array := SA_Set(array, SA_Set(SA_Set("", 9), 3000))
array := SA_Set(array, SA_Set(SA_Set("", 1), 1500))
array := SA_Set(array, SA_Set(SA_Set("", 3), 1500))
array := SA_Set(array, SA_Set(SA_Set("", 7), 1500))


I have a suggestion though. Based on the information you gave, you might want to use the index as the seat number, like this:
Code:
array := SA_Set(array, 1500, 8)
array := SA_Set(array, 3000, 9)
array := SA_Set(array, 1500, 1)
array := SA_Set(array, 1500, 3)
array := SA_Set(array, 1500, 7)
; it automatically allocates blank elements if you set an element past the end of the array

This way whenever you want to see the number of chips seat number X has, just do something like this:
Code:
chips := SA_Get(array, 8) ;gets the number of chips of seat number 8

_________________

Scripts
- License
Back to top
View user's profile Send private message
MattVD



Joined: 03 Mar 2010
Posts: 1
Location: Canada

PostPosted: Sat Mar 06, 2010 5:54 am    Post subject: SA_Len failing to notice when empty variable. Reply with quote

Hello infogulch,

I believe there is an error in your code for SA_Len. It fails to notice when an array is not declared. For example, take the following code:
Code:
   x := SA_Set(x, 1)
   x := SA_Set(x, 2)
   y := SA_Set(y, 3)
   MsgBox, % "Len(x)=" . SA_Len(x) . "  Len(y)=". SA_Len(y) . "  Len(z)=" . SA_Len(z)
   if ErrorLevel
      MsgBox, Caught error in length of an undeclared variable.


The outcome for this code is:
Len(x)=2 Len(y)=1 Len(z)=1
And no MsgBox appears afterwards to indicate that SA_Len ran on an undeclared array (ErrorLevel not set).

Therefore, there is no difference between SA_Len in its output for an array with 1 element or 0 elements, and there is an error.

Could you please take a look at this and tell me what you think?
Thank-you!
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 378

PostPosted: Sat Mar 06, 2010 6:10 am    Post subject: Reply with quote

Actually I have considered this before. A blank variable is considered an array of length 1 as it is no different than initializing the array with a blank first element. Though I would be open to considering modifying this behavior given convincing arguments. At the least I will modify the documentation to mention this specifically.

Thanks Smile
_________________

Scripts
- License
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, 4, 5
Page 5 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