Re: How to use associative arrays in Ada 2005?



Hi!

First, I want to thank all of you for your examples and ideas. But they
don't work, sorry! So, I took your ideas and am trying to implement an
own procedure creating "hashes" like I need them.

The problem is that I need maps of maps of maps ... It's logical that a
container is able to get another container as element and it's no
problem to instanciate these containers and then put them one into the
other.
In my example code I tried to create a table of family names, names
and their ages. Let's make it a little more complex and create another
first key called "nation":

Nation | Family Name | Name | Age*
----------|---------------|---------------------|------
German | Goethe | Johann Wolfgang | 60
| | Catharina Elisabeth | 80
| | Johann Caspar | 90
| Hesse | Hermann | 51
Japanese | Kusanagi | Motoko | 29
American | Ford | Henry | 45
| | Harrison | 41
Finnish | Torvalds | Linus | 35
----------|---------------|----------------------------
* All ages are fictional because I don't know the real
ages of these persons or they are dead or fictional

The problem: Every single key needs a separate container map. We need 1
first-level, 4 second-level and 5 third-level key maps.

First-level = 1x map of string-map
Second-level = 4x map of string-map
Third-level = 5x map of string-integer

It would be necessary to create every single map and to put them one
into the other all manually for transforming the given table into a
"hash". That's easy and possible but not flexible. When posting the
code of my impossible programme, I had the idea of "anonymous"
container maps contained in maps. Because of this I wrote
"Ages.Insert("family name", Insert("name", 23));".

Sadly, Matt's solution didn't work. The statement "Ages.Insert ("family
name", C, B);" brought a compilation error: "no selector 'Insert' for
private type "Ada.Containers.Indefinite_Hashed_Maps.Map" from instance
at line 16". I found out that no procedure "Insert(String, Cursor,
Boolean)" exists. But it exists a procedure "Insert(String,
Element_Type, Cursor, Boolean)".
So, I'm trying to combine Matt's and Georg's ideas now. I'll write a
line, if I'd be successfull. Otherwise, I'll also write a line. ;-)

Once more: Thank you all. I'm commencing to have an idea of Ada-syntax
and philosphy and that's more than my professors at universitiy could
give me.

Greetings,
Matthias

.



Relevant Pages

  • Re: GCC 4.0 Ada.Containers Cursor danger.
    ... We are talking about the Ada 2005 standard container ... of course sets and maps *are* ordered. ... that distinguish vectors and lists on the one side and sets and hashes ... List - a container that provides ordering, but no mapping from it's ...
    (comp.lang.ada)
  • Re: How to use associative arrays in Ada 2005?
    ... Smiths that way. ... if you have filtered out a container with just the Smiths you'd want ... You could have the map of maps of maps, ... The cursors would be ordered according to family-name (that ...
    (comp.lang.ada)
  • Re: GCC 4.0 Ada.Containers Cursor danger.
    ... We are talking about the Ada 2005 standard container ... of course sets and maps *are* ordered. ... Sets and maps are "associative" container, that positions elements in ...
    (comp.lang.ada)
  • Re: Sortable associative container?
    ... > I want to store file objects in a container 8for now, ... > random files from the container in O. ... That's because the main reason why maps are so quick at looking for a ... If you could sort a ...
    (comp.lang.cpp)