From: Erik Hollensbe Date: 2008-10-03T14:16:51+09:00 Subject: Re: Ordered hash hack for < ruby 1.9? Siep Korteling wrote: > The string is always "vkwlaxmbynczodpeqfrgshtiuj" on my machine. There > is no visible logic, but it is predictable and testable. However, the > test may fail when you install the next ruby version, or perhaps when > run on a another platform. > I don't know why your code behaves differently, but if the insertion > order in the hash is not predictable (threads ?), then an ordered hash > won't help. Hash ordering is generally deterministic on read until another write occurs. Then it all depends on the algorithm used to hash the key, if the bucket size was changed and rekeying occured, a number of things. The RHG I believe goes into how hashing algorithms work in ruby, but a good example I can definitely cite is perl 5.6 (and prior)'s hashing algorithm, which if seeded properly could cause it to resize the buckets and re-key so often it could bring system load to DoS levels.... Yes, that's one program, with one hash, with a lot of pairs inserted one at a time, specifically ordered to cause the algorithm to internally resize and rekey on each insert (you know, for performance). There's a bugtraq posting from ... 2002? 2003? that goes into the specific method if you're interested (and yes, it was fixed in 5.8). Anyways, that's not intended as a dig on perl, but basically it's not something to count on, ever. -Erik -- Posted via http://www.ruby-forum.com/.