2011/6/22 Robert Klemme <shortcutter / googlemail.com>:
>> 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 needo do
> a trade off here. What are your requirements anyway?

Ok. I get some data and convert it into a Hash whose key is a priority
value (integer, 0 is the best priority). The value of each entry is of
course the data value associated with such priority. But such hash has
not been ordered, this is, probably entry 1 has priority 2 while entre
2 has priority 1 (or whatever).

Then I just want to get a new hash in which entries are ordered by
priority. I also want to avoid too much Ruby stuff using "hast ->
array -> Array#map(...) -> new has". In this thread it has been
suggested using:

  ordered_hash = Hash[original_hash.sort]

and indeed it works. Yes, it is doing hash->array->hash, but being at
C level I expect it's fast enough.

Regards.



-- 
Iaki Baz Castillo
<ibc / aliax.net>