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

Home » Public Forums » archive » sorting string arrays - non alphabetic and user defined order
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: sorting string arrays - non alphabetic and user defined order [message #50910 is a reply to message #50820] Mon, 23 October 2006 14:03 Go to previous messageGo to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Tue, 17 Oct 2006 06:00:03 -0600, David Fanning wrote:

> Greg Michael writes:
>
>> hmm... it seems to me that 'result' is the array you are looking for:
>> it has the elements in the order you want, and they have the indices
>> numbered from zero (i.e. there are no empty elements).
>
> It seems that way to me, too. But I had to work with
> the solution for a time before I understood it. It
> would have taken me a LONG time to think of using
> indices rather than strings to come up with a solution.
> Perhaps the solution was TOO concise. I've expanded on
> it just a little bit in this article:
>
> http://www.dfanning.com/idl_way/strsort.html

This is similar to the standard inflate and compare WHERE_ARRAY
method. So it would be somewhat simpler (if a bit slower) just to
say:

mylist=mylist[sort(where_array(mylist,namelist,/PRESERVE_ORD ER))]

see turtle.as.arizona.edu/idl/where_array.pro for the modified version
which includes PRESERVE_ORDER.

That said, this exhibits the classic defect of
"scale-em-up-and-compare" methods which the REBIN/REFORM stuff
enables: it starts to get ugly when your comparison vectors get long,
scaling as the product of their lengths, and gobbling up enormous
amounts of memory in the process. We discuss in detail the pros and
cons of the various methods here:

http://www.dfanning.com/tips/set_operations.html

For long vectors, you'll be better off with a sort-based algorithm
(e.g. ind_int_SORT, see above):

mylist=mylist[sort(ind_int_sort(namelist,mylist))]

JD
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: path to .sav file
Next Topic: Re: Retrieving the title of a widget_base after the fact.

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

Current Time: Sun Oct 12 00:02:30 PDT 2025

Total time taken to generate the page: 0.01666 seconds