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



Joined: 24 Nov 2007
Posts: 766

PostPosted: Tue Oct 14, 2008 7:24 pm    Post subject: Reply with quote

But the pipe character is the delimiter, right? The encoding and decoding functions seem to specifically encode only the pipe (delimiter) and % (encoding character), and decode just those back to the same.:

Quote:
SA_Enc( Val )
{
StringReplace, Val, Val, `%, `%e, All ; e(ncoding char)
StringReplace, Val, Val, |, `%d, All ; d(elimeter char)
return Val
}

SA_Dec( Val )
{
StringReplace, Val, Val, `%d, |, All ; d(elimeter char)
StringReplace, Val, Val, `%e, `%, All ; e(ncoding char)
return Val
}

_________________
Ben

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



Joined: 27 Mar 2008
Posts: 378

PostPosted: Tue Oct 14, 2008 7:30 pm    Post subject: Reply with quote

bmcclure wrote:
Your data can contain the pipe character ... so pipes will be encoded and decoded correctly at each level.
Exactly, so you don't need to worry about passing anything strange into the functions, I'll be encoded properly and retrieved just as well. So, as long as you use my functions to access and modify the array, you should be fine putting pretty much anything in it.

Yes, it will support named indexes when I release the next version. No duplicate names will be allowed. A valid name is any string that is non-blank and is not a number. (pretty broad, huh? Razz ) (still no worries about pipe chars in names, they're encoded too Smile ) I'm also releasing a way of getting nested array values.

I've nearly got the rewrite done, but probably won't finish it till next week. It should not break any current application of SA.
_________________

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



Joined: 24 Nov 2007
Posts: 766

PostPosted: Tue Oct 14, 2008 7:36 pm    Post subject: Reply with quote

Very Happy *drool*

I can hardly wait for the rewrite with named indexes. It will make my Games and Tools arrays sooo much easier to work with in SteamLab!

Thanks for the cool functions!
_________________
Ben

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



Joined: 27 Mar 2008
Posts: 378

PostPosted: Tue Oct 14, 2008 7:42 pm    Post subject: Reply with quote

lol, you guys are fast! Very Happy I'm three posts behind! Razz

Right now, the pipe character IS the delimiter, and it's encoded whenever it's put into the array. I am seriously considering changing the delimiter and encoding characters to control chars. Like the EOT and ENQ chars. (asc 5 and 6) There would be no change in functionality, only that there is less chance for someone to pass a value with it inside.

Thanks for your support Smile
_________________

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



Joined: 13 Dec 2006
Posts: 48

PostPosted: Tue Oct 14, 2008 7:57 pm    Post subject: Reply with quote

That's a good idea.
Something like '\0' (NUL) would basically never be inputted (or technically will always be inputted, but never put in the array), it would be kind of like strtok-ing in C. Though back when I was thinking about doing that the best one I came up with was BS (Backspace). BEL is also never used anymore. EOT (^d) is still used on unix systems and various input terminals, so it may cause some problems. Though, I dont think DOS (or Windows) uses it...


Last edited by olegbl on Tue Oct 14, 2008 8:21 pm; edited 1 time in total
Back to top
View user's profile Send private message
bmcclure



Joined: 24 Nov 2007
Posts: 766

PostPosted: Tue Oct 14, 2008 8:17 pm    Post subject: Reply with quote

Can you even use nulls logically in AHK? I thought it stopped at the first null character found, even if it were in the middle of the string?

I've had to come up with functions that replace nulls to get AHK to read past them at all when I've had to read things like Bencoded files and Steam's settings file.

Maybe that wouldn't be an issue in SA, but since it just uses standard string functions, wouldn't the null characters still need to be replaced with something else to be able to return anything after the first one?

But I guess even if so, there are a lot of characters besides null that could be used.
_________________
Ben

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



Joined: 13 Dec 2006
Posts: 48

PostPosted: Tue Oct 14, 2008 8:21 pm    Post subject: Reply with quote

Well, that's the point of nulls, they now mean (though not originally) that the string is ended. Then again, considering AHK doesn't store strings as pointers, it might forget about anything after the NUL. If it doesn't however, then the null would be used as the delimiter. Such as in strsplit. I haven't tested this so I'm not sure they would work properly, but if they do, they would probably be the most appropriate character...
Back to top
View user's profile Send private message
bmcclure



Joined: 24 Nov 2007
Posts: 766

PostPosted: Tue Oct 14, 2008 8:29 pm    Post subject: Reply with quote

I think you would not be able to use standard functions to retrieve values after the first null in an array however. For instance, once I import a file with nulls into it as a variable, AHK does keep the data after the first null (until after you use other functions which don't see that data and save back to the variable), but you can't retreive that data without first removing any nulls before it. At least, this was my experience previously, unless something has changed.

If there is an efficient way around this problem, or if I'm mistaken, then I think a null character would be an excellent choice.
_________________
Ben

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



Joined: 27 Mar 2008
Posts: 378

PostPosted: Tue Oct 14, 2008 9:10 pm    Post subject: Reply with quote

Yes. NULL is not even recognized as a param in ahk's commands/functions. So, for now I'll use BS and BEL chars. It shouldn't change anything, except maybe a bit less en/decoding.

I believe it is possible to work with strings past a null char using regex. I may do that someday, but it would have to be a v4 Razz.
_________________

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



Joined: 22 May 2008
Posts: 120

PostPosted: Tue Oct 14, 2008 11:29 pm    Post subject: Reply with quote

I’ll be looking forward to this update. I’d also be curious as to benchmarking the basic functions vs. a loop/parse statement. Seems like I end up doing way too many stringsplits and loop/parses in ahk, just to retrieve the results of one pseudo-array variable. Thanks again for this library.
Back to top
View user's profile Send private message
lwjiee



Joined: 12 Jul 2008
Posts: 8

PostPosted: Tue Oct 21, 2008 7:05 pm    Post subject: Bug report Reply with quote

Thank you for sharing your work very greatful! It is vary easy to use, give me a lot of help.
When i ues , i found a problem with SA_Del() . Sample like that:
Code:
Ary1 = a|b|c
Ary2 = d|e|f

MsgBox % "Adding one array as an element in another:`nArray2:`t"
   . Ary2 "`nInside:`nArray1:`t"
   . Ary1 "`nBecome:`t"
   . Ary1 := SA_Set(Ary1,Ary2,4)

MsgBox % "Delet an element in the end of a Array:`n"
   . Ary1 := SA_Del(Ary1,4)

I found you lost think with StringGetPos return error.
The original code in SA_Del():
Code:
Dir = R

changed to:
Code:
rDir = R

The original code in SA_Del():
Code:
StringGetPos, lPos, Array, |, % lDir lIdx
   StringGetPos, rPos, Array, |, % rDir rIdx
   lStr := SubStr(Array, 1, lPos)
   rStr := SubStr(Array, rPos+2)

changed to:
Code:
StringGetPos, lPos, Array, |, % lDir lIdx
   StringGetPos, rPos, Array, |, % rDir rIdx
   If ErrorLevel
      rStr := ""
   Else
      rStr := SubStr(Array, rPos+2)
   lStr := SubStr(Array, 1, lPos)

And i also change the SA_Dec():
Code:
SA_Dec( Val )
{
   StringReplace, Val, Val, `%@*,  |, All ; d(elimeter char)
   StringReplace, Val, Val, `%$#, `%, All ; e(ncoding char)
   return Val
}

SA_Enc as the same. Because i worried "%d" may appear in the content of array itself.
Your code so smart make me shock!
It's the first post of me in here . I'm llook forward the greatest Array lib.
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 378

PostPosted: Tue Oct 21, 2008 8:52 pm    Post subject: Reply with quote

lwjiee wrote:
And i also change the SA_Dec() ... SA_Enc as the same. Because i worried "%d" may appear in the content of array itself.
Your code so smart make me shock!
Thank you! I haven't been able to work on it for a couple days, but I have a new, improved version that I will probably release this weekend. It includes being able to get values in nested arrays, and using named indexes. Thanks for noting the errors, I will look them over, but the new version is a rewrite, so may not need these updates.

The encoding and decoding setup work flawlessly with whatever you throw at it, including "%d" or "%e". (ok, maybe not NULL, but I don't see how you could put that in the array anyway. Razz ) So it is unnecessary to change it to unlikely strings.

A quick example of how it works:
Code:
SA_Set(array, "%d")
MsgBox %array%
SA_Set(array, "%e", 2)
MsgBox %array%

MsgBox % SA_Get(array)
MsgBox % SA_Get(array, 2)

_________________

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



Joined: 29 Jul 2005
Posts: 179

PostPosted: Wed Oct 22, 2008 1:43 am    Post subject: Reply with quote

infogulch wrote:
I have a new, improved version that I will probably release this weekend. It includes being able to get values in nested arrays, and using named indexes.
Hooray! Thanks for this.. it is extremely useful.

I especially look forward to seeing how your going to implement the named indexes. Very Happy
_________________
.o0[ corey ]0o.
Back to top
View user's profile Send private message
bmcclure



Joined: 24 Nov 2007
Posts: 766

PostPosted: Wed Oct 22, 2008 4:53 pm    Post subject: Reply with quote

I especially look forward to using the named indexes Smile

Getting a little tired of looping through arrays to find a particular value.

A find function, and named indexes, will eliminate the need to loop at all in most cases Very Happy
_________________
Ben

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



Joined: 12 Jul 2008
Posts: 8

PostPosted: Wed Oct 22, 2008 5:12 pm    Post subject: Reply with quote

oh, great, it looks easy with 3D or nD arrays.

I want to ask you two question ,
question one ,why code like that:
Code:
SA_Del( ByRef Array, fmIdx, toIdx="" )

without ByRef, it still works..
question two ,why
Code:
SA_Get(SA_Get(array,n),m)

does't ,but
Code:
SA_Get(blank := SA_Get(array,n),m)

works
I'm confused with BuRef, like this
http://www.autohotkey.com/forum/viewtopic.php?t=36982
Thank you very much!
[/quote]
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  Next
Page 2 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