From: Robert Klemme Date: 2004-12-03T23:42:41+09:00 Subject: Re: ordered hash ? "David A. Black" schrieb im Newsbeitrag news:Pine.LNX.4.44.0412030621130.4637-100000@wobblini... > Hi -- > > On Fri, 3 Dec 2004, Robert Klemme wrote: > > > > > "David A. Black" schrieb im Newsbeitrag > > news:Pine.LNX.4.44.0412030519240.28725-100000@wobblini... > > > Hi -- > > > > > > On Fri, 3 Dec 2004, Robert Klemme wrote: > > > > > > > Hm, I'd prefer the "natural" order of key elements, i.e. the order > > defined > > > > by <=>. > > > > > > The problem is, though, that keys can be anything, including things > > > that don't respond to <=> or that can't be meaningfully compared with > > > other keys. > > > > But that's okay: you'll get bitten by an exception if you insert such > > keys. It will work perfectly for the most common key types (I guess these > > are String and maybe Fixnum). If you want such keys then you can easily > > define your own ordering with the lambda you provide. > > There may be a lot of hashes with such keys, but I wouldn't describe > that uniformity as more "natural" to a hash than the act of key/value > insertion itself. I meant "natural" to refer to the ordering of the instance class. I guess I didn't make that clear enough. But yes, I'd use that as the default ordering of a hash, too. :-) > I guess I'd prefer to see hash order be a > characteristic of every hash (without an exception raised), regardless Please, not of every Hash - just the OrderedHashes. IMHO space and time overheads are significant enough to not include this into every hash. > of the keys, and then have things like ordering by string value, etc., > be the more specialized case. Well, I beg to differ for stated reasons. Let's see what Matz and others think about this. Kind regards robert