Re: How to use associative arrays in Ada 2005?
- From: "Dmitry A. Kazakov" <mailbox@xxxxxxxxxxxxxxxxx>
- Date: Mon, 27 Nov 2006 10:15:21 +0100
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
.
- Follow-Ups:
- Re: How to use associative arrays in Ada 2005?
- From: Matthew Heaney
- Re: How to use associative arrays in Ada 2005?
- References:
- How to use associative arrays in Ada 2005?
- From: snoopysalive
- Re: How to use associative arrays in Ada 2005?
- From: Matthew Heaney
- Re: How to use associative arrays in Ada 2005?
- From: snoopysalive
- Re: How to use associative arrays in Ada 2005?
- From: snoopysalive
- Re: How to use associative arrays in Ada 2005?
- From: Dmitry A. Kazakov
- Re: How to use associative arrays in Ada 2005?
- From: Matthew Heaney
- Re: How to use associative arrays in Ada 2005?
- From: snoopysalive
- How to use associative arrays in Ada 2005?
- Prev by Date: Re: Multitasking and containers
- Next by Date: Re: Multitasking and containers
- Previous by thread: Re: How to use associative arrays in Ada 2005?
- Next by thread: Re: How to use associative arrays in Ada 2005?
- Index(es):
Relevant Pages
|
|