Projects

Ticket #290 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

Hashes do NOT stay ordered

Reported by: martin.ploeger@… Owned by: eloy.de.enige@…
Priority: blocker Milestone: MacRuby 0.6
Component: MacRuby Keywords: Hash order
Cc:

Description

Hashes in Ruby 1.9 keep their order. In MacRuby (macirb):

{:aa=>1, :a=>1}

=> {:a =>1, :aa=>1}

According to Ruby 1.9 the result should be in the input-order:

=> {:aa =>1, :a=>1}

The same is true for methods on a Hash like Hash#keys: The should return the keys in the input-order.

Change History

  Changed 3 years ago by lsansonetti@…

We don't support input-ordered hash keys because our Hash class is based on top of CFDictionary. We may support this in the future using a hack but it's really not a high-priority item on the agenda.

  Changed 3 years ago by eloy.de.enige@…

We could port ActiveSupport::OrderedHash to our Hash implementation:  http://github.com/rails/rails/blob/master/activesupport/lib/active_support/ordered_hash.rb

I suppose that would be like the ‘hack’ Laurent suggests.

follow-up: ↓ 6   Changed 3 years ago by conradwt@…

ActiveSupport implementation of Hash is probably activated when using Ruby < 1.9.1 because it's in Ruby 1.9.1. With that said, I would take a look at the C implementation of Hash located here:

 http://redmine.ruby-lang.org/repositories/entry/ruby-191/hash.c

  Changed 3 years ago by conradwt@…

Is there a Ruby spec which fails in this regard? If not, I believe it should be one which fails to provide a hint for something to fix in the future.

follow-up: ↓ 7   Changed 3 years ago by lsansonetti@…

By hack I was thinking about patching a little bit our Hash implementation. But as I said I don't think this is very important for the time being.

FYI, there is a Ruby spec that covers this 1.9-only behavior. It's currently failing on MacRuby.

in reply to: ↑ 3   Changed 3 years ago by eloy.de.enige@…

  • owner changed from lsansonetti@… to eloy.de.enige@…

Replying to conradwt@…:

ActiveSupport implementation of Hash is probably activated when using Ruby < 1.9.1 because it's in Ruby 1.9.1. With that said, I would take a look at the C implementation of Hash located here:  http://redmine.ruby-lang.org/repositories/entry/ruby-191/hash.c

By porting OrderedHash, I meant we could port it to our CF implementation. Not to use the ruby version of itself :) It should contain all the necessary tweaks needed to support ordering. I might have a stab at this at some point.

in reply to: ↑ 5   Changed 3 years ago by conradwt@…

Replying to lsansonetti@…:

By hack I was thinking about patching a little bit our Hash implementation. But as I said I don't think this is very important for the time being. FYI, there is a Ruby spec that covers this 1.9-only behavior. It's currently failing on MacRuby.

What's the syntax for running both the pre-Ruby 1.9 and Ruby 1.9 specs?

  Changed 2 years ago by pthomson@…

  • status changed from new to closed
  • resolution set to fixed

This has been fixed in trunk thanks to Laurent's refactorings to Hash (I believe in r3345).

kid-a:MacRuby local$ macirb
irb(main):001:0> {:aa=>1, :a=>1}
=> {:aa=>1, :a=>1}
irb(main):002:0> {:c => 1, :b => 2, :a => 3}
=> {:c=>1, :b=>2, :a=>3}

  Changed 2 years ago by lsansonetti@…

  • milestone set to MacRuby 0.6
Note: See TracTickets for help on using tickets.