15 May 18:35
Re: Access Hash in the same order that was created
From: Gregory Seidman <gsslist+ruby <at> anthropohedron.net>
Subject: Re: Access Hash in the same order that was created
Newsgroups: gmane.comp.lang.ruby.general
Date: 2008-05-15 16:35:55 GMT
Subject: Re: Access Hash in the same order that was created
Newsgroups: gmane.comp.lang.ruby.general
Date: 2008-05-15 16:35:55 GMT
On Fri, May 16, 2008 at 01:22:56AM +0900, Mario Ruiz wrote: > I need to access to a Hash in the same order that It was created: [...] > is that possible? First off, this is not a hash. Hashes are inherently unordered. Hashes provide amortized O(1) insertion and retrieval of elements by key, and that's it. If you need an ordered set of pairs, use an array of arrays. Yes, this is a pet peeve of mine. There was an OrderedHash that someone wrote, but needing it is an indication of a design problem. It has also been obsoleted by the Dictionary in Ruby Facets. One could argue that, like Java, there should be a standard Dictionary interface that Hash implements, and that there should be another implementation that preserves order without guaranteeing anything about performance. That's not how things stand right now. > Thanks --Greg
RSS Feed