Use .get() in MultiD Assoc Array?

Philippe Sigaud philippe.sigaud at gmail.com
Thu Aug 30 12:40:34 PDT 2012


On Thu, Aug 30, 2012 at 9:30 PM, Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> I believe that if you want a map (be it ordered or unordered) to give you
> items back in the order that you inserted them, then a separate list is
> required (be it integrated into the container or something you do alongside
> it) where that list has the keys in the order that they were inserted into the
> container.

Yes, that's what I wanted to propose. Group an AA and a standard,
dynamic, array. The array is just filled with the key, when you assign
a new key/value pair. To query the structure, use the AA. To print the
structure in order, iterate on this array of keys and query the AA
accordingly.

Of course, there is a downside:

* when you discard a key/value pair, your key array must be iterated
to find the now-discarded key and recreated after the key.
* when you re-assign an already defined key, you might want to put the
key in front/back of the array once more.

Pro: in order printing/iteration.
Con: slow discarding, slow re-assigning.


More information about the Digitalmars-d-learn mailing list