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

Home » Public Forums » archive » Re: Sort a HASH
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: Sort a HASH [message #76754 is a reply to message #76664] Fri, 24 June 2011 15:28 Go to previous message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
Hi all,

The reason this isn't working is because when you index a hash, you
get back another hash. It doesn't matter the order of the keys when
you do the indexing, IDL will create a new hash with the desired key/
value pairs, and they will be in whatever order the hash determines.

A way around this is to just get both the keys & values out, then sort
on those:

h=hash(['a','c','d','b'],[7,1,5,8])
keys = (h.KEYS()).toArray()
val = (h.VALUES()).toArray()
s = SORT(keys)
print, keys[s], val[s]

a b c d
7 8 1 5

If you were worried about making an extra copy of the values, you
could use a foreach loop instead:

foreach key, (h.KEYS())[s] do print, key, h[key]
a 7
b 8
c 1
d 5
This will work in IDL 8.1.

Perhaps a better approach would be for us to add a SORT keyword to the
KEYS() method. So you could do something like:
foreach key, h.KEYS(/SORT) do print, key, h[key]

What do you all think about that?

-Chris
ITTVIS
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Connecting GPC to IDL
Next Topic: PostScript Window Size

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

Current Time: Fri Oct 10 02:08:50 PDT 2025

Total time taken to generate the page: 0.48015 seconds