From: gwtmp01@... Date: 2006-08-15T01:52:44+09:00 Subject: Re: A use case for an ordered hash On Aug 14, 2006, at 12:15 PM, Martin DeMello wrote: > On 8/14/06, Austin Ziegler wrote: >> On 8/14/06, Martin DeMello wrote: >> > OHash or Assoc or even Dict (though the latter at least implies >> an O(1) lookup). >> >> Wouldn't it be the same as Hash lookup? It's still got every other >> characteristic of a Hash; it just guarantees an order that >> defaults to >> insertion order. > > True, I suppose you could do it with a doubly linked list overlaid on > a hash. Was thinking of sorted order. Can't you just maintain an internal array representing the key insertion order? Something like: class OHash < Hash # ... def each keyseq.each { |k| yield k, self[k] } end end Where keyseq is just an array that is updated whenever keys are added/deleted? Gary Wright