Forum: JRuby Is hash ordered in JRuby 1.1?

A7d7f5db5a4f72544d08913bcd3d4514?d=identicon&s=25 Barbara McInnes (Guest)
on 2008-06-12 17:45
(Received via mailing list)
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
40e5e9fe36a1f85166493faac2c17499?d=identicon&s=25 Hirotsugu Asari (Guest)
on 2008-06-12 19:51
(Received via mailing list)
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]
Ede2aa10c6462f1d825143879be59e38?d=identicon&s=25 Charles Oliver Nutter (Guest)
on 2008-06-14 08:46
(Received via mailing list)
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
40e5e9fe36a1f85166493faac2c17499?d=identicon&s=25 Hirotsugu Asari (Guest)
on 2008-06-14 16:58
(Received via mailing list)
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
E9b3caa1e06657bd49d20d6583b6916d?d=identicon&s=25 Joshua Hull (Guest)
on 2008-06-14 17:11
(Received via mailing list)
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
Ede2aa10c6462f1d825143879be59e38?d=identicon&s=25 Charles Oliver Nutter (Guest)
on 2008-06-14 20:18
(Received via mailing list)
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
40e5e9fe36a1f85166493faac2c17499?d=identicon&s=25 Hirotsugu Asari (Guest)
on 2008-06-14 20:21
(Received via mailing list)
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
A7d7f5db5a4f72544d08913bcd3d4514?d=identicon&s=25 bemmi (Guest)
on 2008-06-16 10:44
(Received via mailing list)
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
This topic is locked and can not be replied to.