comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: How to use associative arrays in Ada 2005?
Date: Mon, 27 Nov 2006 10:15:21 +0100
Date: 2006-11-27T10:15:22+01:00	[thread overview]
Message-ID: <1tt24us1dtxxk$.4j9ua533yewd$.dlg@40tude.net> (raw)
In-Reply-To: 1164567954.228842.32980@h54g2000cwb.googlegroups.com

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



  parent reply	other threads:[~2006-11-27  9:15 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-21 10:11 How to use associative arrays in Ada 2005? snoopysalive
2006-11-21 11:49 ` Georg Bauhaus
2006-11-21 14:18 ` Matthew Heaney
2006-11-21 23:35   ` snoopysalive
2006-11-23 19:27     ` snoopysalive
2006-11-23 19:40       ` Georg Bauhaus
2006-11-24  0:33       ` Georg Bauhaus
2006-11-24 11:49         ` Matthew Heaney
2006-11-24  8:27       ` Dmitry A. Kazakov
2006-11-24 11:51         ` Matthew Heaney
2006-11-26 19:05           ` snoopysalive
2006-11-26 20:30             ` Matthew Heaney
2006-11-27  9:15             ` Dmitry A. Kazakov [this message]
2006-11-27 19:53               ` Matthew Heaney
2006-11-27 21:11                 ` Dmitry A. Kazakov
2006-11-27 21:52                   ` Matthew Heaney
2006-11-28  8:29                     ` Alex R. Mosteo
2006-11-28 13:19                       ` Matthew Heaney
2006-11-28  8:34                     ` Dmitry A. Kazakov
2006-11-28 13:21                       ` Matthew Heaney
2006-11-27 21:08             ` Simon Wright
2006-11-27 22:22               ` Matthew Heaney
2006-11-27 22:58                 ` Simon Wright
2006-11-28  1:55                   ` Matthew Heaney
2006-11-24 11:35       ` Matthew Heaney
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox