On Tue, Jun 21, 2011 at 6:34 PM, Iki Baz Castillo <ibc / aliax.net> wrote:
> 2011/6/21 Iki Baz Castillo <ibc / aliax.net>:
>> 2011/6/21 Robert Klemme <shortcutter / googlemail.com>:
>>> See Adam's and Josh's replies: a Hash is generally unordered.
>>> However, what do you need this for?    
>>> then you might as well override #inspect on a per instance basis or
>>> change it in Hash (not recommended).
>>
>> Hi, I don't understand your comment.
>
> Sorry, my dog pressed "sent mail".

LOL That's what our cat didn't manage yet - although he is trying hard
by walking over the keyboard if I am not watchful enough.

> I meant that I don't understand the point of your comments. In Ruby
> 1.9 Hashes are ordered. I cannot change the order after creating them,
> but if you inspect elements of a Hash you get them in the order in
> which they were inserted. This is valid and useful for me (in my
> case).

I thought you want a different ordering (based on key).

>>> If you need that for other
>>> reasons then maybe a tree might be a better choice.    >>> example
>>> http://raa.ruby-lang.org/project/ruby-rbtree/
>
> I already worker with rbtree. The only difference (or one of them) is
> the way in which keys are inserted. rbtree requires all the keys being
> the same class. In my tests rbtree is better for deleting elements but
> worse than a Hash for inserting them.

<snip>benchmark</snip>

Now I am confused.  What do you need?  A fast data structure?  An
ordered data structure?  What is more important?  You will need to do
a trade off here.  What are your requirements anyway?

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/