From: Robert Dober Date: 2009-07-30T01:21:45+09:00 Subject: Re: Indexing hash with longer strings faster? 2009/7/29 Mladen Jablanović : > You pointed to the right direction here! > > Although your example gives me 100 as result (all the hashes are > unique), here's what suggests that hash collision indeed is the reason > of the slowness: > >>> [*0..99].map{|i| [*0..99].map{|j| [i.to_s,j.to_s].hash}}.flatten.uniq.size > => 1756 >>> [*0..99].map{|i| [*0..99].map{|j| [i.to_s + '00000',j.to_s + '00000'].hash}}.flatten.uniq.size > => 10000 OMG my code was sloppy, but you got it right, here is the 1.9 code 506/18 > cat hashes.rb && ruby -v hashes.rb #!/usr/local/bin/ruby -w # encoding: utf-8 # file: /home/robert/log/ruby/ML/hashes.rb p [*0..99].map{|i| [*0..99].map{|j| [i.to_s,j.to_s].hash}}.flatten.uniq.size p [*0..99].map{|i| [*0..99].map{|j| [i.to_s + '00000',j.to_s + '00000'].hash}}.flatten.uniq.size # vim: sts=2 sw=2 ft=ruby expandtab nu : ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-linux] 10000 10000 as expected :). Cheers Robert > > Can you please just post the ruby 1.9 results here? > > Thanks! > > -- Toutes les grandes personnes ont d’abord été des enfants, mais peu d’entre elles s’en souviennent. All adults have been children first, but not many remember. [Antoine de Saint-Exupéry]