comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Sort without loops
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Sort without loops [message #45166] Wed, 17 August 2005 02:08 Go to previous message
Ian Dean is currently offline  Ian Dean
Messages: 26
Registered: January 2000
Junior Member
Hi All,
I have a large string array (~100000 elements) that need sorting on two
fields within each string.

e.g. array=['F;100', 'ABC;6', 'DE;2', 'DE;10', 'DE;1']

Order required is a) sort items to left of ';' followed by b) sort items
numerically to right of ';'
This would produce:
ABC;6 DE;1 DE;2 DE;10 F;100

A simple sort (sort(array)) procudes:
ABC;6 DE;1 DE;10 DE;2 F;100

The only way I've found is to conmvert the RH part to I4.4 format within a
loop and search on the new values:
......
for j=0, n_elements(array)-1 do begin
parts=strsplit(array[j], ';', /extract)
RH=string(fix(parts[1]), format='(I4.4)')
new[j]=parts[0]+RH
endfor
order=sort(new)
...
i.e
new array is F;0100 ABC;0006 DE;0002 DE;0010 DE;0001
which is then sorted correctly.

Is there a clever way of sorting on two fields like this without using a
loop. The above algorithm is faaaar slower than just using sort.

I hope I have made this as clear as mud.#

In expectation,
Ian
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: WIDGETS
Next Topic: y,z title rotation

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 20:09:20 PDT 2025

Total time taken to generate the page: 0.01756 seconds