Re: How to use associative arrays in Ada 2005?



Simon Wright <simon@xxxxxxxxxxxx> writes:

But that only works for the first map. You couldn't find all the
Smiths that way.

If that's what you're after, you need (in database terms) a second
independent index.

Right. In the GNAT distribution there's an examples directory that includes
some container examples. The library example does what you suggest, using
multiple containers to provide the necessary query support.


I've just read (and re-read, and re-read) A.18.5(43) and I see what
you mean. Perhaps it's a bit late. I had read 'same hash =>
equivalent' whereas it's actually 'equivalent => same hash'.

Right.


If you have as your key a record comprising the 3 strings (nation,
family name, given name), then "=" would be adequate for
Equivalent_Keys.

I would have a record with (nation, family_name, given_name, age) --
if you have filtered out a container with just the Smiths you'd want
to know the other facts for each of them, too.

You could have the map of maps of maps (as in the OP), and use another
container (an ordered multiset, say) whose elements are cursors designating a
family-name/(given-name/age) map. (Using cursors means you never have to
duplicate data.) The cursors would be ordered according to family-name (that
is, by the key that the cursor points to).

Actually, there are probably many ways to do it. During the design of the
container library, both the container and cursor types were declared as
definite and non-limited specifically to facilitate the kinds of composition as
in your example.
.



Relevant Pages

  • Re: GCC 4.0 Ada.Containers Cursor danger.
    ... Cursors are a special case, they should be marked as such. ... > same semantics for _any_ container type. ... > i.e. access types; they require no cursors. ... Algorithm can use internally whatever it needs to deliver ...
    (comp.lang.ada)
  • Re: GCC 4.0 Ada.Containers Cursor danger.
    ... To impose an order on them standard needs to put a restriction on implementarion algorithms. ... There is no need for cursors during iterations. ... has exactly the same semantics for _any_ container type. ... This could be done using a generic algorithm which is similar ...
    (comp.lang.ada)
  • Re: GCC 4.0 Ada.Containers Cursor danger.
    ... had one after the other through iteration using cursors. ... This could be done using a generic algorithm which is similar ... When I'm can use any container, ... Imagine programming without indirection, whatever the indirection mechanism looks like. ...
    (comp.lang.ada)
  • Re: GCC 4.0 Ada.Containers Cursor danger.
    ... then that is your own business. ... > If make container remember all its cursors we can implement ... You have complete freedom to do so. ...
    (comp.lang.ada)
  • Re: GCC 4.0 Ada.Containers Cursor danger.
    ... > I look in all my Ada programs. ... There are a few loops per container, ... Most programs will have no cursors at all, or only one in stored in a local ... If you care about checks, ...
    (comp.lang.ada)