Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[lib] SimpleArray - short & fast string array - v3.5


  • Please log in to reply
82 replies to this topic
Rigel
  • Members
  • 9 posts
  • Last active: May 09 2010 04:32 PM
  • Joined: 22 Apr 2010
edit: Thanks for your support, I made some suggestion but now I implement my own arrays script totally different from SimpleArray. However SimpleArray is a great script.
Bye

tuna
  • Members
  • 158 posts
  • Last active: Dec 28 2012 04:50 PM
  • Joined: 03 Oct 2007
Thanks infogulch for the library.

However, it's a bit problematic setting a second element without a first, as the first delimiter is removed and the array is reduced by the first (empty) element:
Array1 := SA_Set(Array1, "Value", 1, 0)
Array2 := SA_Set(Array2, "Value", 2, 0)
msgbox %Array1%`n%Array2%
produces:
---------------------------
test.ahk
---------------------------
Value
Value
---------------------------
OK   
---------------------------

########################################################
Also, it seems that overwriting with named indexes is a bit flaky as I find I end up losing the name despite not specifying GiveName.
Array := SA_Set(Array, "Value1", 1, "+1", "name")
Array := SA_Set(Array, "Value2", "name", 0)
msgbox %Array%
produces
---------------------------
test.ahk
---------------------------
Value2
---------------------------
OK   
---------------------------
Additionally, although the recognition of names appears to be case sensitive, specifying names appears not to be case sensitive since
Array := SA_Set(Array, "Value1", 1, "+1", "name")
Array := SA_Set(Array, "Value2", "name", 0, "NAME")
msgbox %Array%
still gives me
---------------------------
test.ahk
---------------------------
Value2
---------------------------
OK   
---------------------------

########################################################
I have also found that the _Find... functions do not take into account named indices, such that an element with name "Name" and value "Needle" (stored as "Name:Needle") does not constitute a whole match for the needle "Needle". Additionally,
Loop 3
	Array := SA_Set(Array, "Needle", A_Index, 0)
msgbox % Array "`n" SA_FindCnt(Array, "Needle")
returns
---------------------------
test.ahk
---------------------------
NeedleNeedleNeedle
2
---------------------------
OK   
---------------------------
since it appears that the find is based on matching the needle preceded by the delimiter. However, the first element is never preceded by a delimiter.

Perhaps it may be worthwhile to use the delimiter to denote elements instead, so that every element is preceded/followed by "", i.e., store [ele1, ele2, ... , eleN] as
ele1ele2 ... eleN ; or
ele1ele2 ... eleN
otherwise you will keep having to find various ways to account for the first element separately (i.e. having to change counts by +/-1 or have to check the last item separately in the SA_FindCnt() etc.), which is just a constant pain to do, and just requires more lines of code and leaves space for bugs.

########################################################
; !Important Note:
; ! The nIdx in SA_Set and Idx in SA_Set_ now only accept names or indexes
; ! and the "add to end + option" is now in the opt param ...
SA_Set( Array, Val, nIdx="1", opt="+1", giveName="" )
Finally, it might be a good idea to update this to the main post as it still says

Number Index: (param name Idx may only be a number)
If you want to add a value at the end of the array with SA_Set() use '+' as the first character and the number following will be counted as an offset from the end of the array. This allows you to add it arbitrarily farther than the end. (Note that the default index param is '+1' so you can add it to the end without specifying a number yourself)
...
SA_Set( Array, Val, [nIdx="+1", Insert=false, giveName=""] )

which initially gave me a fair bit of confusion.

Also, since most other languages overwrites elements of the array by default so that Array[j] := "Value" sets the j'th element to "Value", I found it a little counter-intuitive that by default the equivalent in SA, SA_Set(Array, "Value", j), puts it j elements off the end of the array by default. Indeed, the first time I tried creating an array of [1,2,3] (using AHKA notation), I was surprised to find that
Array := SA_Set(Array, "Value1", 1)
Loop 3
	Array := SA_Set(Array, "Value2", 2)
MsgBox %Array%
produced
---------------------------
test.ahk
---------------------------
123
---------------------------
OK   
---------------------------
although this is just down to personal intuition.


Thanks


AHK v1.0.48.5

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
Wow, thank you tuna for your time spent on this, I really appreciate it and will check these things out.

I've been working on the next version for some time now but haven't released it. During development it got to the point where when I fixed one thing it started breaking another thing, so I implemented a bunch of unit tests, which is probably the best thing I've done with this library so far. Among other things I greatly simplified calling the set function, as it was getting out of hand.

If you like, pm me and I'll get you a copy of the current beta (which I will probably bump to v4.0). Currently it only fails one of the SA_Trim unit tests and otherwise works fine.

By the way, the raw arrays are not intended to be viewed directly. Instead, you should use the SA_Join function to view them (such as in a messagebox). It also helps in the forum because the forum doesn't properly display the delimiter character and it is confusing when trying to read your bug reports. For example, SA_Join(Array1,"|")

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
@infogulch: good to hear you are still working on it. As requested a number of times in this thread and ask for help, some documentation with examples would be appreciated by many.

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
hugov: yes, the documentation for this script has always been poor at best. That is something else I'm working on.

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
Ok, so here's a beta version for those who would like to test it: SimpleArray-v3.6.ahk

The biggest change is the revamped Set function. Docs: SimpleArray-Docs-v3.6.txt

The following functions are either known to be broken or are probably broken: Unique, Shift, Swap, ConvertPsuedo, ConvertDelimited, and Join

I still need to create unit tests for the above functions, but the functions Set, Get, Del, Trim, Len, Find, FindCnt, and Sort work perfectly afaik.

If you find a bug with the (purportedly) working functions, please please send me a condensed version of what reproduces the bug and I will fix it and add a unit test to make sure it doesn't happen again.

lzlgboy
  • Members
  • 2 posts
  • Last active: Oct 14 2011 09:21 AM
  • Joined: 09 Dec 2009
The download SimpleArray.ahk contains some strange character when open with notepad, and can not work.

  • Guests
  • Last active:
  • Joined: --
That is on purpose, those "strange" characters are asc 5 & 7 if I recall correctly, they are used as delimiters in the array.
Note that you can use real arrays and objects with AutoHotkey_l and that there are a number of array libraries posted here which should be easier to use. Simple Arrays is meant mostly for use with AutoHotkey basic, so it is recommended to download the latest AutoHotkey via the download page.