From: Robert Klemme Date: 2008-09-03T22:58:18+09:00 Subject: Re: Hash optimization question 2008/9/3 Robert Dober : > On Wed, Sep 3, 2008 at 11:24 AM, Robert Klemme > wrote: > >> I guess it will be difficult to get both: fast hash lookup and >> insertion on one hand and fast iteration on the other hand. Is it >> worth the effort? I don't know. This depends on your application. >> Where is this a problem for you? Maybe there is a more efficient data >> structure for your particular problem. > Long time not having been on the same thread Robert:) :-) > Well indeed I would suggest to anyone having problems with performance > of small hashes to have a look at Array#assoc and #rassoc. The only > problem is I do not know up to which number of pairs this behaves > well. I guess n<20 should be quite safe. Maybe I will find some time > to benchmark this later. Binary search might be an additional option for small to medium sized collections if retrieval speed is not paramount but iteration speed is important. (Btw, do we have binary search in the std lib by now? This should probably go into Array...) Kind regards robert -- use.inject do |as, often| as.you_can - without end