From: Karsten Meier Date: 2012-01-23T19:15:52+09:00 Subject: Re: uniq with count; better way? If your data items are integers, and from a rather small range (compared to computer memory...), then you can use an array instead of an hash: maxval = 10 result = Array.new(maxval+1, 0) ar.each{ |x| result[x] += 1; } This returns an array and not an hash. [0, 0, 0, 0, 2, 2, 3, 1, 0, 0, 0] To make a histogram, that data structure is even better. Otherwise you need to transform it to a hash again. But for large data sets I still expect it to be faster: Your cpu does not need to calculate a hash key of every single data item, because the data item is already a perfect key for the array. Also no hash key collisions can occur. Regards Karsten Meier -- Posted via http://www.ruby-forum.com/.