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

Home » Public Forums » archive » Re: HASH -- bug, or "feature"?
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: HASH -- bug, or "feature"? [message #75876 is a reply to message #75875] Wed, 20 April 2011 12:50 Go to previous messageGo to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
It's not a bug or a feature. It's a property of hashes. And it's not peculiar to IDL. E.g. from the Ruby pickaxe:

<quote>
Compared with arrays, hashes have one significant advantage: they can use any object as an index. However, they also
have a significant disadvantage: their elements are not ordered.
</quote>

Similarly with Python dictionaries.

Typically the need for hashes where insertion order is important leads to a subclass of Hash being created where the
order is internally tracked.

cheers,

paulv



Gray wrote:
> Can anyone tell me why, when you create a hash, the elements are not
> in the order of the keys you give? And, even worse, when you index a
> hash with an array of keys, the resulting hash does not come out in
> the same order as the array?
>
> IDL> h = hash(['a','b','c','d'],indgen(4))
> IDL> print, h
> c: 2
> a: 0
> b: 1
> d: 3
> IDL> print, h[['a','c','d']]
> c: 2
> a: 0
> d: 3
>
> This is making my bookkeeping using hashes basically impossible.
>
> --Gray
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: HASH -- bug, or "feature"?
Next Topic: IDL syntax highlighting for GeSHI

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

Current Time: Fri Oct 10 00:33:18 PDT 2025

Total time taken to generate the page: 0.16026 seconds