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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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!news2.google.com!news4.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.news.pas.earthlink.net.POSTED!14bb18d8!not-for-mail Sender: Matthew Heaney@MHEANEYIBMT43 Newsgroups: comp.lang.ada Subject: Re: How to use associative arrays in Ada 2005? References: <1164103903.240838.37230@j44g2000cwa.googlegroups.com> <1164152113.623461.130190@e3g2000cwe.googlegroups.com> <1164310051.811802.237400@l12g2000cwl.googlegroups.com> From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 24 Nov 2006 11:35:31 GMT NNTP-Posting-Host: 4.238.121.243 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.news.pas.earthlink.net 1164368131 4.238.121.243 (Fri, 24 Nov 2006 03:35:31 PST) NNTP-Posting-Date: Fri, 24 Nov 2006 03:35:31 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news2.google.com comp.lang.ada:7683 Date: 2006-11-24T11:35:31+00:00 List-Id: "snoopysalive" writes: > And now, my next question: How to handle "hashes of hashes" in Ada? You have to make two distinct instantiations. > procedure book is > package Str_Int_Maps is > new Ada.Containers.Indefinite_Hashed_Maps > (String, > Integer, > Ada.Strings.Hash, > "="); > use Str_Int_Maps; > package Str_Map_Maps is > new Ada.Containers.Indefinite_Hashed_Maps > (String, > Str_Int_Maps.Map, > Ada.Strings.Hash, > "="); > > Ages : Str_Map_Maps.Map; -- That's the "hash of a hash" > > begin > Ages.Insert("family name",Insert("name",23)); > end book; > -- Here, the code ends You have to make two distinct insertions. The first uses the form of Insert that inserts a key and a default element value (the element here is itself another map), and the second uses an in-place update to insert a key/elem pair into the secondary map. Something like: declare C : Str_Map_Maps.Cursor; B : Boolean; begin -- this is the insert that inserts an element with its -- "default value" into the map: Ages.Insert ("family name", C, B); -- first insert -- C now designates the map we care about (note that -- it doesn't matter what value B has) declare procedure Update (S : String; -- the family name M : in out Str_Int_Maps.Map) is begin M.Insert ("name", 23); -- second insert end; begin Ages.Update_Element (C, Update'Access); end; end; > The statement "Ages.Insert("family name",Insert("name",23));" doesn't > work. So, how is it possible to do something like this in C++: > "... > map> ages; > ages["family name"]["name"] = 23; > ..." Ada doesn't have an index operator, so it's not going to be as concise as the C++. If you're doing this a lot then you can always refactor the code above into its own stand-alone operation. Something like: procedure Insert (M : in out Str_Map_Maps.Map; Family_Name : String; Name : String; Age : Integer) is ... -- as above