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=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:ae9:c218:: with SMTP id j24mr16794129qkg.60.1572361347725; Tue, 29 Oct 2019 08:02:27 -0700 (PDT) X-Received: by 2002:aca:180a:: with SMTP id h10mr4497278oih.30.1572361347363; Tue, 29 Oct 2019 08:02:27 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!85.12.16.70.MISMATCH!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.am4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!j16no693722qtl.0!news-out.google.com!x9ni459qti.1!nntp.google.com!j16no693718qtl.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 29 Oct 2019 08:02:26 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=136.163.208.2; posting-account=HFCrOQoAAABZD_f-UUbYHm3lJDIrh-UX NNTP-Posting-Host: 136.163.208.2 References: <6ea868a2-6f4b-413c-955d-08e8735f2880@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <1559a685-7483-4f2f-8674-d7b61c23bfe8@googlegroups.com> Subject: Re: How to Iterate over all elements of a hashed_map. From: joakimds@kth.se Injection-Date: Tue, 29 Oct 2019 15:02:27 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Bytes: 2745 X-Received-Body-CRC: 466547281 Xref: reader01.eternal-september.org comp.lang.ada:57370 Date: 2019-10-29T08:02:26-07:00 List-Id: Den tisdag 29 oktober 2019 kl. 15:20:43 UTC+1 skrev Alain De Vos: > I found code which takes a different approach, here there is a function .Iterate public ... , > > with Ada.Containers.Indefinite_Hashed_Maps; > with Ada.Strings.Hash; > > with Ada.Text_IO; use Ada.Text_IO; > > procedure Show_Hashed_Map is > > package Integer_Hashed_Maps is new > Ada.Containers.Indefinite_Hashed_Maps > (Key_Type => String, > Element_Type => Integer, > Hash => Ada.Strings.Hash, > Equivalent_Keys => "="); > > use Integer_Hashed_Maps; > > M : Map; > -- Same as: M : Integer_Hashed_Maps.Map; > begin > M.Include ("Alice", 24); > M.Include ("John", 40); > M.Include ("Bob", 28); > > if M.Contains ("Alice") then > Put_Line ("Alice's age is " > & Integer'Image (M ("Alice"))); > end if; > > -- Update Alice's age > -- Key must already exist in M. > -- Otherwise an exception is raised. > M ("Alice") := 25; > > New_Line; Put_Line ("Name & Age:"); > for C in M.Iterate loop > Put_Line (Key (C) & ": " & Integer'Image (M (C))); > end loop; > > end Show_Hashed_Map; I confirm that when you want to iterate over a hashed map and want both key and value you need to use the .Iterate function as you do in the example. Best regards, Joakim