Ordering an associative array - or - another option

Era Scarecrow rtcvb32 at yahoo.com
Thu Jun 7 23:39:44 PDT 2012


On Wednesday, 6 June 2012 at 17:05:35 UTC, Jonathan M Davis wrote:
> On Wednesday, June 06, 2012 16:04:14 Paul wrote:
>> I have and array string[string][string][string] that works 
>> great for everything I need except that they (assoc. arrays) 
>> don't maintain an order. I need to maintain the order of entry.
>>
>> Are there any work arounds that others have used? I saw some 
>> tricks in the book for sorting a single dimensional assoc. 
>> array. Thanks to all!
>
> If you want an ordered map, then use 
> std.container.RedBlackTree. It's a little bit annoying to use 
> as a map (you basically have to use it as a set of pairs/tuples 
> which are ordered on their first member), but it's quite doable 
> (and is what C++'s STL does internally with std::map). Chaining 
> them like you seem to be trying to do though would probably get 
> ugly though.

  Agreed, it would get ugly and looks like difficult right off the 
bat, since RedBlackTree's are classes you'll need to initialize 
them on each level, or have a general purpose one with two 
purposes and they chain internally... Hmmm... maybe...


More information about the Digitalmars-d-learn mailing list