Hi all, Do hashes maintain insertion order in JRuby 1.1? I would like to take a JRuby hash to a Java LinkedHashMap and maintain insertion order throughout. Thanks, Barbara
on 2008-06-12 17:45
on 2008-06-12 19:51
Hi there. It appears that it (JRuby 1.1.2) does maintain insertion
order, but that is different from MRI (1.8.6-p111).
$ jirb
irb(main):001:0> h={:a=>1,:b=>2}; h.delete(:a); h[:a]=3; h.keys
=> [:b, :a]
$ irb
irb(main):001:0> h={:a=>1,:b=>2}; h.delete(:a); h[:a]=3; h.keys
=> [:a, :b]
on 2008-06-14 08:46
Hirotsugu Asari wrote: > Hi there. It appears that it (JRuby 1.1.2) does maintain insertion > order, but that is different from MRI (1.8.6-p111). > > $ jirb > irb(main):001:0> h={:a=>1,:b=>2}; h.delete(:a); h[:a]=3; h.keys > => [:b, :a] Note that 1.8.6 does not maintain insertion ordering in any way. JRuby maintains exact insertion ordering, where deleted keys re-set will show up later in the sequence. - Charlie --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2008-06-14 16:58
On Jun 14, 2008, at 1:45 AM, Charles Oliver Nutter wrote: > > - Charlie Right. And I think it is a bad idea to write code that relies on JRuby's (current) insertion-order-preserving behavior. Hiro --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2008-06-14 17:11
However, Ruby 1.9 preserves hash ordering, so maybe this isn't such a bad thing. Joshua On 14-Jun-08, at 10:57 AM, Hirotsugu Asari wrote: >> JRuby maintains exact insertion ordering, where deleted keys re-set > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2008-06-14 20:18
Joshua Hull wrote: > However, Ruby 1.9 preserves hash ordering, so maybe this isn't such a > bad thing. On 14-Jun-08, at 10:57 AM, Hirotsugu Asari wrote: > Right. And I think it is a bad idea to write code that relies on > JRuby's (current) insertion-order-preserving behavior. It's probably not such a bad idea...it's specified behavior now in Ruby 1.9 that insertion order is preserved for operations where it makes sense (like keys, each, etc). It was specifically added. - Charlie --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2008-06-14 20:21
On Jun 14, 2008, at 1:17 PM, Charles Oliver Nutter wrote: > makes sense (like keys, each, etc). It was specifically added. > > - Charlie Thank you both Joshua and Charlie for clarifying this. Hiro --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2008-06-16 10:44
Brilliant. Maintaining exact insertion order suits me perfectly. Thanks! -- View this message in context: http://www.nabble.com/Is-hash-ordered-in-JRuby-1.1... Sent from the JRuby - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.