From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC,T_FILL_THIS_FORM_SHORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,693e247f5dca709d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.karotte.org!uucp.gnuu.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: How to use associative arrays in Ada 2005? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1164103903.240838.37230@j44g2000cwa.googlegroups.com> <1164152113.623461.130190@e3g2000cwe.googlegroups.com> <1164310051.811802.237400@l12g2000cwl.googlegroups.com> <14xluht6idlik$.1cxod3mnfvcfs.dlg@40tude.net> <1164567954.228842.32980@h54g2000cwb.googlegroups.com> Date: Mon, 27 Nov 2006 10:15:21 +0100 Message-ID: <1tt24us1dtxxk$.4j9ua533yewd$.dlg@40tude.net> NNTP-Posting-Date: 27 Nov 2006 10:15:22 CET NNTP-Posting-Host: f63161d7.newsspool4.arcor-online.net X-Trace: DXC=BJfDYGe^=cQ<<0iRN7DLEQ4IUK 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