2011/6/22 Robert Klemme <shortcutter / googlemail.com>:
> Well, in that case an Array would be much more efficient. You just
> need a way to deal with holes, e.g.
>
> prio_data = []
>
> def prio_data.each_pair
> each_with_index do |x,i|
>  yield i, x if x
> end
> end
>
> prio_data[1] = "foo"
> prio_data[4] = "bar"
>
> prio_data.each_pair {|prio,v| printf "key=%p val=%p\n", prio, v}

Interesting approach :)


>> Then I just want to get a new hash in which entries are ordered by
>> priority.
>
> Why do you need a second container object? Is this just for sorting
> purposes or do you actually need to maintain the state from a given
> point in time?

The second container (an ordered one) will be passed (later) to a
method which randomizes each DNS result based on its SRV weight. So
first I need a contained in which DNS records are ordered by priority,
and later a randomize method (already done) which shorts the array
entries of each priority value based on entries weight (randomly of
course, but taking into account the weight of each SRV record).

I've it already working, but I will take a more deepth look to your
above code to integrate it.

Thanks a lot.



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