# is it smarter way for this ?

 08 August 2010 Thorn444 New Member Peter Kerpcar Bratislava, Slovakia is it smarter way for this ? Hi I have been trying again do some maxscript stuff and come to part of script where i am looking for some variable inside array which is created from point3 values and i would like to know if is any better, faster and smarter way how deal with this. My biggest issue is that i cant find any other way how search inside this values only by converting them into new integer array which i don't think is very efficient. So what do you think can you make this easier ? Thanks my result `````` a = 5 -- searching for value 5 c =#() d =#() b = #([4,1,5],[3,6,5],[9,8,7]) -- array for search for j = 1 to b.count do ( c_temp = #() d_temp = #() for i = 1 to 3 do append c_temp (b[j][i] as integer) -- convert [] array into integer value append c c_temp d_temp = finditem c[j] a append d d_temp ) d `````` share quote
 08 August 2010 Bobo Krakatoa Guy   Borislav Petrov Product Specialist Thinkbox Software Vancouver, Canada MAXScript is expression-based, so using intermediate variables to store the various stages of calculations, while allowed and possible, are not always necessary. So you can reduce the whole searching part to a single complex expression: ``````a = 5 -- searching for value 5 b = #([4,1,5],[3,6,5],[9,8,7]) -- array for search result = for j in b collect (finditem (for i = 1 to 3 collect j[i]) a)`````` The result will be the same #(3,3,0), but with a lot less intermediate results. On the plus side, the code will run a bit faster if you are searching through a lot of Point3 values or if you execute the same code many times because intermediate variable allocations and memory management cost time. I tested your code vs. mine with 100,000 iterations and my timing was 7.688 seconds vs. 10.109 seconds for your code. On the negative side, the above expression might be a lot more difficult to digest if you are seeing it for the first time... __________________ Bobo Last edited by Bobo : 08 August 2010 at 07:07 PM. share quote
 08 August 2010 Thorn444 New Member Peter Kerpcar Bratislava, Slovakia hehe yes this is exactly what I was talking about. Quick and efficient how I wanted. I just didn't know the right words Thanks Bobo share quote
 08 August 2010 denisT MAX Doctor   portfolio Denis Trofimov CA, USA has to be a bit faster: `````` a = 5 b = #([4,1,5],[3,6,5],[9,8,7]) for p in b collect (finditem #(p[1],p[2],p[3]) a) `````` or ... it looks ugly but it's 3.5 times faster and 15 times less of memory leaking (vs original code): `````` a = 5 b = #([4,1,5],[3,6,5],[9,8,7]) for p in b collect (if p[1] == a then 1 else if p[2] == a then 2 else if p[3] == a then 3 else 0) `````` so, the smart way is not charming sometime. Last edited by denisT : 08 August 2010 at 09:50 PM. share quote
 08 August 2010 Thorn444 New Member Peter Kerpcar Bratislava, Slovakia Hi DenisT I know i didn't mention this in my post but I was thinking about much more way which you can use generally , because i guess your both version can be use only if you know how much numbers you have in array or for small array how I used in my example array and I must maybe mention that. But anyway thanks for another option how deal with collecting stuff quicker and efficient. Cheers share quote
 08 August 2010 denisT MAX Doctor   portfolio Denis Trofimov CA, USA Originally Posted by Thorn444: Hi DenisT I know i didn't mention this in my post but I was thinking about much more way which you can use generally , because i guess your both version can be use only if you know how much numbers you have in array or for small array ... Cheers I guess that Point3 value has 3 members... Last edited by denisT : 08 August 2010 at 11:08 PM. share quote
 08 August 2010 CGTalk Moderation Expert Thread automatically closed This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum. __________________ CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.