From: Robert Klemme Date: 2006-09-08T15:10:33+09:00 Subject: Re: Faster datastructure for lookups wanted m94asr@gmail.com wrote: > Hi all, > > maybe somebody can recommend me the right datastructure or > any other advice would be a big help. > > My code spends most of its execution time doing lookups from > a hashtable with about 1M keys. The keys are strings and the values > are arrays of integers. Most of the time only of length 1. > > I do not care how long the construction of the datastructure takes, > but the lookup should be as fast as possible. > > xs.each{|x| > if found = hash[x] > #do sth. > end > } As others said already, a Hash is pretty much the fastest for the general case. How do your string keys look like? Maybe it is worth trying symbols instead of strings? If you unveil a bit more about your application we might be able to come up with more suggestions. Kind regards robert