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, 6  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Thu Feb 05, 2009 6: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: 774

PostPosted: Thu Feb 05, 2009 9: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 3: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: 649

PostPosted: Wed Jun 03, 2009 6: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
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Wed Jun 03, 2009 8: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
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Mon Jun 08, 2009 11:10 pm    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
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Thu Jun 11, 2009 11:49 am    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
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Thu Jun 11, 2009 2: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
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Thu Jun 11, 2009 6: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
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Aug 19, 2009 9: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: 649

PostPosted: Wed Aug 19, 2009 2: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 4: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: 649

PostPosted: Sat Mar 06, 2010 5: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
Rigel



Joined: 22 Apr 2010
Posts: 9

PostPosted: Thu Apr 22, 2010 7:16 pm    Post subject: Reply with quote

Hi,
Thanks for your simplearray.
I have a little problem:
Code:

#Include simplearray_v3.5_rel.ahk


elemArray := SA_Set(elemArray,"a",1,false,"AAA")
elemArray := SA_Set(elemArray,"b",2,false,"BBB")
elemArray := SA_Set(elemArray,"c",3,false,"CCC")
elemArray := SA_Set(elemArray,true,4,false,"bool")   
elemArray := SA_Set(elemArray,"d",5,false,"DDD")   
myArray := SA_Set(myArray,elemArray,SA_Len( myArray )+1,false, "myArray1")
     

resetVisible("myArray1",false)    
    
resetVisible(name,bool)
{

   global myArray
   elem := SA_Get(myArray,name)
   
   ;pretest
   pretest := SA_Get(elem,"bool")
   indexByName := SA_Idx( elem,"bool")   
   len := SA_Len( elem )   
   outputDebug pretest %pretest% index: %indexByName% len: %len%
   outputDebug %elem%
   outputDebug ------------------------------------------------
   ;pretest 1 index: 4 len: 5   
   ;AAA:aBBB:bCCC:cbool:1DDD:d   
   
   ;test 1, set without index
   elem := SA_Set(elem,bool,"bool")         
   test1 := SA_Get(elem,"bool")
   indexByName1 := SA_Idx( elem,"bool")   
   len1 := SA_Len( elem )
   outputDebug test1 %test1% index: %indexByName1% len: %len1%
   outputDebug %elem%   
   outputDebug ------------------------------------------------
   ;test1 1 index: 4 len: 9   
   ;AAA:aBBB:bCCC:cbool:1DDD:d0   
   ;no value change but length rises to 9
   
   elem := SA_Get(myArray,name)
   
   ;test 2 with index
   elem := SA_Set(elem,bool,4,false,"bool")         
   test2 := SA_Get(elem,"bool")
   indexByName2 := SA_Idx( elem,"bool")   
   len2 := SA_Len( elem )
   outputDebug test2 %test2% index: %indexByName2% len: %len2%
   outputDebug %elem%
   outputDebug ------------------------------------------------
   ;test2 AAA:aBBB:bCCC:c0DDD:d index:  len: 5   
   ;AAA:aBBB:bCCC:c0DDD:d   
   ;length ok but the value is all the array and bool:1 become 0
   elem := SA_Get(myArray,name)
   
   ;test 3 with index and without name
   elem := SA_Set(elem,bool,4)         
   test3 := SA_Get(elem,"bool")
   indexByName3 := SA_Idx( elem,"bool")   
   len3 := SA_Len( elem )
   outputDebug test3 %test3% index: %indexByName3% len: %len3%
   outputDebug %elem%   
   outputDebug ------------------------------------------------
   ;test3 1 index: 4 len: 9   
   ;AAA:aBBB:bCCC:cbool:1DDD:d0   
   ;the same of test1
   
   
   myArray := SA_Set(myArray,elem,SA_IdxName(myArray,name),false, name)
   
   

}

- How can I change a value?
- There's a way to change a value in child array without reassign the child array to parent array?
- There's a function to change a value like this elem := SA_change(elem,newVal,name)?

Thanks.

p.s. My real project have a more complex structure with 3 array level and many function so I post a simplest test Smile
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Thu Apr 22, 2010 10:01 pm    Post subject: Reply with quote

Quote:
- How can I change a value?

Notes Section in file wrote:
; ! 2.Specify zero or nothing as the second character to overwrite the element
; ! at Idx position, otherwise any positive number to insert Val into that position


I'm sorry this wasn't clear. I'm also sorry that SA_Set() is kindof kludgy to use. Confused

Quote:
- There's a way to change a value in child array without reassign the child array to parent array?

Not currently. SA_Get() does support nested arrays, but not SA_Set() as of now.

I'm going to think hard about changing SA_Set() because, honestly, it sucks right now.
_________________
Scripts - License
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 5 of 6

 
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