Hi,

At Thu, 20 Feb 2003 16:04:03 +0900,
Bulat Ziganshin wrote:
> i think that better way to speed up this code is:
> 
> h = data.scan(iptok).sort.uniqc.to_hash

Sort and uniq are O(n*log(n)) and O(n) respectively, whereas
counting with hash is O(n).

> where
> Array#to_hash - reverse operaqion to Hash#to_a

What do you define "reverse" operation?  Hash from pairs of
keys and values?

However, that method would be lossive, so the name "to_hash"
might not be appropriate.  In fact, once I've suggested similar
method but it was rejected due to the doubt whether it's the
expected behavior to "to_hash".

> and these two methods must be included in Ruby itself, because they support
> very widespread programming idioms

Agree to "to_hash", at least.

-- 
Nobu Nakada