From: Robert Klemme Date: 2007-11-22T21:54:18+09:00 Subject: Re: Ordered Hash Usefulness 2007/11/21, MenTaLguY : > On Thu, 22 Nov 2007 05:25:07 +0900, Robert Klemme wrote: > >> In Ruby 1.8 the enumeration order of a Hash is undefined, in Ruby 1.9, > >> unless it's been backed out recently, it's defined as above. > > > > Does Ruby 1.9 really impose the overhead to maintain insertion order for > > *every* Hash? > > I asked matz about that on ruby-core. The overhead turns out to be very > small; 1.9 maintains a doubly-linked list of hash elements, which has > constant-time insertion and removal. Yeah, clearly. > Memory overhead is two words per > hash element. I'm less concerned with the CPU overhead but rather the memory overhead. > We may implement the 1.9 ordering in JRuby soon, as it solves a number of > problems with concurrency and iterator stability. Hm, concurrently iterating and modifying is a bad idea anyway IMHO. But I can see how some issues can be resolved with this. I just think that making this impl. the default for all Hashes might have some adversary effects. I'd rather leave the old impl as is and add another (sub) class that has the ordered behavior. Kind regards robert -- use.inject do |as, often| as.you_can - without end