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,ce306343df782d85 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!newsread2.news.atl.earthlink.net.POSTED!14bb18d8!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada Subject: Re: Newbie - HashMap! References: <1111061037.535775.69180@l41g2000cwc.googlegroups.com> <42399f5c$0$26540$9b4e6d93@newsread4.arcor-online.net> 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: Mon, 21 Mar 2005 00:33:08 GMT NNTP-Posting-Host: 24.149.57.125 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.news.atl.earthlink.net 1111365188 24.149.57.125 (Sun, 20 Mar 2005 16:33:08 PST) NNTP-Posting-Date: Sun, 20 Mar 2005 16:33:08 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:9653 Date: 2005-03-21T00:33:08+00:00 List-Id: Georg Bauhaus writes: > package Lookup_tables is > new Ada.Containers.Hashed_Maps (Unbounded_String, > Unbounded_String, > Equivalent_Keys => "=", > Hash => Hash); Strictly speaking, the C++ example used type std::string, and the Ada analog of that type is probably Unbounded_String, so what you have above is technically correct. However, Ada doesn't have constructors like you have in C++, that automatically convert a const char* to std::string, so what you have above is going to be awkward to use. Therefore, I recommend the indefinite hashed map instead: package Lookup_Tables is new Ada.Containers.Indefinite_Hashed_Map (String, String, Hash, "="); Now you can using type String directly: Include (HM, "Key", "Value"); --yes: Include, not Insert Note that this code is probably wrong: > procedure ex is > > use Lookup_Tables; > > hm: Map; > begin > hm.insert(To_Unbounded_String("key"), To_Unbounded_String("value")); > end ex; The reason is that the 3-parameter Insert will raise Constraint_Error if the key is already in the map. You probably want to use Include instead, which replaces the old value with the new value, if the key already exists. See above.