From: joakimds@kth.se
Subject: Re: How to Iterate over all elements of a hashed_map.
Date: Tue, 29 Oct 2019 08:02:26 -0700 (PDT)
Date: 2019-10-29T08:02:26-07:00 [thread overview]
Message-ID: <1559a685-7483-4f2f-8674-d7b61c23bfe8@googlegroups.com> (raw)
In-Reply-To: <bfdcdb58-0aa9-42f5-a487-52f21dfa8ffd@googlegroups.com>
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
next prev parent reply other threads:[~2019-10-29 15:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-29 13:43 How to Iterate over all elements of a hashed_map Alain De Vos
2019-10-29 14:20 ` Alain De Vos
2019-10-29 15:02 ` joakimds [this message]
2019-10-29 21:56 ` Randy Brukardt
2019-10-29 16:48 ` Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox