From: "Iñaki Baz Castillo" Date: 2011-06-22T23:19:54+09:00 Subject: Re: How to order a hash based on its keys? 2011/6/22 Robert Klemme : > Hm...  Now I am not sure any more whether you need a associative > container at all.  Now we have three steps.  From what I understand > you do: > > 1. items are collected > 2. items are ordered by priority (what you call second container above) > 3. items are ordered by some randomization algorithm > > I'm obviously missing other access operations out here.  So far I > don't see any need for a Hash or similar structure.  What else is it > that you need to do with these items?  What properties do they have? Step 1) I get data (DNS SRV records), which is an array with entries like this: # Each entry is a SRV record. It has a priority (lowest value is the best) and weight (higher value means more probability to choose it). The client getting such array of SRV records wants to connect to a server based on SRV priorities/weight, which works as follows: - SRV records with best priority must be used first. - If there are various SRV records with same priority, then the probability of choosing each one depends on its weight value (random with weight). - If the chosen SRV record fails to connect (i.e. server down) next one (based on same priority/weight rules) must be tryed. -- Iñaki Baz Castillo