Notifications
Clear all

[Closed] sort array problem

this is the right direction… and as you can see you can do ‘index to integer’ with pre-process as well.

but when we check the performance we have to include pre-process (its time and memory use) in whole sorting process measurement.

anyway it will be better than the pure sorting method without ‘pre-processing’

I’m very far to understand c++ solution
Anyway what about python solution? Is it faster then c# or …

i don’t remember built-in python natural sorter. in python people usually use regex and split…
i do it for example this way:

def sortkey_natural(s, end=1):
 	     splitkey = r'(\d+$)' if end else r'(\d+)')
 	     return tuple(int(part) if re.match(r'(\d+$)', part) else part for part in re.split(splitkey, s))

we can stay with mxs… but with a little help from c#. and the numbers for test above (20000 unsorted names) will be:

time:129  memory:1280704L

not bad, isn’t it?

It’s bed because is perfect and many of us do not understand real power of c++.
Thanks for this lesson.

this is how to do this task with c#

import from “shlwapi.dll” StrCmpLogicalW method

write IComparer

use Array.Sort with this comparer

for mxs using just make c# assembly (i would do on-the-fly assembly)
and mxs code might look as

dotnetarray = dotnet.valuetodotnetobject mxsarray (dotnetclass "System.String[]")
(dotnetclass "System.Array").Sort dotnetarray comparer
dotnetarray.clone()
1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Yep. I tried this morning the same :

  • generate .net string array using valuetodotnetobject method
  • use array sort method
    I know to load assembly “shlwapi.dll” but not know how to create function for comparer that will be later use for sorting. I saw c# examples stuck with IComparer.
1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

NICE! Are you used this for previous speed and memory test?
It’s not funny. For me is difficult to understand and especialy to write this code.
Still result by using this assembly is perfect like I said.
This solution can not be beat.
Thanks again.

it can be. if we will do sorting in-place. but it needs max SDK.

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Previous solution is good enough. Please no more c++

OH! my god ,Denis Trofimov,big brother,I love you, Thank you veryyyyyyyyy much!
:bowdown: :bowdown: :bowdown: :bowdown:

THANK Branko Živković for discussion,THANKS AGAIN!

created 200 spheres ,i compared these methods in speed and memory,hope it useful to newbie like me.

method of Branko Živković:
time:0.031s memory:17700L

method of Jorge Rodríguez:
time:0.172s memory:135060L

method of Branko Živković:
1)time:0.031s memory:44740L
2)time:0.016s memory:1148L

method of Denis Trofimov:
1.Mscript) time:0.031s memory:334060L
2.net): time:0.016s memory:1968L

Page 2 / 3