Re: How to use associative arrays in Ada 2005?



On 26 Nov 2006 11:05:54 -0800, snoopysalive wrote:

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

No, this is still a 3D array of age. Mathematically it is always equivalent
to an array of arrays of arrays of age. Both are mappings which for a tuple
(Nation, Surname, Name) yield age.

The problem: Every single key needs a separate container map.

That depends on each concrete case. Arrays of arrays have advantages and
disadvantages. It is to expect a performance penalty in terms of both space
and time for an hash of hash of hash vs. simple hash. Clearly, instead of
one look-up you are doing three.

P.S. Arrays of arrays usually come in question only when you would like to
perform searches on subarrays. Like: find all Nation="German". And only
when there is a fixed order on the indices. For example, find all
Name="John" would work awfully.

P.P.S. Hashes aren't equivalent to associative arrays. Hash is one of many
possible implementations of. It again has advantages and disadvantages. For
example, hashes are unsuitable for searching for the best match (like:
Nation="...", Name="..." etc). Here things like kd-trees are used.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.



Relevant Pages

  • Re: How to use associative arrays in Ada 2005?
    ... Arrays of arrays have advantages and ... and time for an hash of hash of hash vs. simple hash. ... Insertion and deletion in sparse 3D arrays organized in hashes of hashes ... The bottom line is - I think a good advice to a student learning Ada, ...
    (comp.lang.ada)
  • Re: Idiot Q: How to find index number of HASH match?
    ... Here are two hash tables, ... Hashes don't have 'links'. ... Hashes do not have index numbers and they don't have arrays. ... least) two choices for keeping your hash keys in order: ...
    (comp.lang.perl.misc)
  • Re: hash of hashes & arrays
    ... I have a hash of data, this hash is very big with dynamic elements ... (strings, numbers, hashes, arrays) ... elsif ($ref eq 'HASH') { ...
    (perl.beginners)
  • Re: Reading next line, finding missing number in sequence
    ... Bowsayge created a program that seems ... Your code shows a very plausible use of a hash. ... With sets of integers it can be of advantage to use arrays for the ... representation instead of hashes, especially if the integers are small. ...
    (comp.lang.perl.misc)
  • trying to understand hash of hashes or multidimensional arrays
    ... I've read dozens of postings about 'hashes of hashes' and ... unknown number of levels, in each level an unknown number of locations, ... multidimensional array (or should it be a 'hash of hashes'?). ... arrays and then having elements of arrays referring to other arrays, ...
    (comp.lang.perl.misc)