From: "Jesús Gabriel y Galán" Date: 2009-02-03T00:44:19+09:00 Subject: Re: Quicker finding strings? Alternative for array, hash, set? On Mon, Feb 2, 2009 at 3:37 PM, Patrick Put wrote: >> If you do not want to attach information to those words then a Set is >> more appropriate: same O(1) lookup but no key value mapping. > Is the implementation "under the hood" the same? That would mean my > choice to use a Set was not so bad after all. If you check here: http://www.ruby-doc.org/core/classes/Set.html you can see the source code for each method. For example this is the method new: # File lib/set.rb, line 64 def initialize(enum = nil, &block) # :yields: o @hash ||= Hash.new enum.nil? and return if block enum.each { |o| add(block[o]) } else merge(enum) end end So you can see, it uses a Hash underneath. Let's take a look at the add method: # File lib/set.rb, line 195 def add(o) @hash[o] = true self end So, it's using a hash with true as the values (the same I did in my example). Of course, if the true doesn't mean anything to you (which shouldn't as you are not using the values), using a Set is a bit more clear, and has convenience methods for Set "arithmetic". Jesus.