CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 07-12-2013, 05:23 PM   #16
DaveWortley
<database error>
 
DaveWortley's Avatar
portfolio
David Wortley
Technical Director
London, United Kingdom
 
Join Date: Dec 2004
Posts: 1,845
Send a message via MSN to DaveWortley
100
1000
10000

Yeah I'm not going to try 100000

OK
sortCorrect()
sortIncorrect()
correct iterations:399 time:1 memory:3392L
#(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...)
incorrect iterations:1165 time:3 memory:38096L
#(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...)
OK
sortCorrect()
sortIncorrect()
correct iterations:3332 time:10 memory:159016L
#(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...)
incorrect iterations:86508 time:157 memory:4818376L
#(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...)
OK
sortCorrect()
sortIncorrect()
correct iterations:36699 time:74 memory:2023344L
#(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...)
incorrect iterations:8388633 time:16438 memory:23001380L
#(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...)


So by having my function as...

Code:
Case of ( ((v1[2]) == (v2[2]) and (v1[1] < v2[1])) : -1 ((v1[2]) == (v2[2]) and (v1[1] > v2[1])) : 1 ((v1[2]) < (v2[2])) : -1 ((v1[2]) > (v2[2])) : 1 default: 0 )


I Should be ok?
__________________
Maxscript Made Easy...
http://davewortley.wordpress.com/
 
Old 07-12-2013, 05:31 PM   #17
PolyTools3D
Expert
 
PolyTools3D's Avatar
portfolio
Jorge Rodríguez
Argentina
 
Join Date: Jun 2013
Posts: 1,120
Quote:
Originally Posted by denisT
this is the base c# sort function (sort by first and by next) :
Code:
public static object[][] Sort(object[][] array) { Array.Sort(array, delegate(object[] x, object[] y) { int result = (x[0] as IComparable).CompareTo(y[0]); return (result != 0) ? result : (x[1] as IComparable).CompareTo(y[1]); }); return array; }

array of several types (integer, float, string) max automatically converts to object[]


Thank you Denis!
And for Point2/Point3 they should be converted to array first?

#( #([1,1,1],[2,2,2],[3,3,3]), #([4,4,4],[5,5,5],[6,6,6]) )
#( #(#(1,1,1),#(2,2,2),#(3,3,3)), #(#(4,4,4),#(5,5,5),#(6,6,6)) )
__________________
Jorge Rodríguez
PolyTools3D
 
Old 07-12-2013, 05:40 PM   #18
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,421
Send a message via ICQ to denisT
Quote:
Originally Posted by PolyTools3D
Thank you Denis!
And for Point2/Point3 they should be converted to array first?

#( #([1,1,1],[2,2,2],[3,3,3]), #([4,4,4],[5,5,5],[6,6,6]) )
#( #(#(1,1,1),#(2,2,2),#(3,3,3)), #(#(4,4,4),#(5,5,5),#(6,6,6)) )

true... only three base mxs types max aromatically converts to .net array (object)... also arrays of .net objects (classes)
 
Old 07-12-2013, 06:13 PM   #19
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,421
Send a message via ICQ to denisT
Quote:
Originally Posted by DaveWortley
So by having my function as...
Code:
Case of ( ((v1[2]) == (v2[2]) and (v1[1] < v2[1])) : -1 ((v1[2]) == (v2[2]) and (v1[1] > v2[1])) : 1 ((v1[2]) < (v2[2])) : -1 ((v1[2]) > (v2[2])) : 1 default: 0 )


I Should be ok?

that's OK. but if you would count the worse case you see that it needs make 6 comparisons.
why? if you can do the same for only 4?
Code:
fn sortByIndex v1 v2 = if (v1[2] < v2[2]) then -1 else if (v1[2] > v2[2]) then 1 else if (v1[1] < v2[1]) then -1 else if (v1[1] > v2[1]) then 1 else 0
 
Old 07-12-2013, 06:13 PM   #20
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:37 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.