A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
43
Task/Hash-from-two-arrays/Ada/hash-from-two-arrays.ada
Normal file
43
Task/Hash-from-two-arrays/Ada/hash-from-two-arrays.ada
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
with Ada.Strings.Hash;
|
||||
with Ada.Containers.Hashed_Maps;
|
||||
with Ada.Text_Io;
|
||||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
||||
|
||||
procedure Hash_Map_Test is
|
||||
function Equivalent_Key (Left, Right : Unbounded_String) return Boolean is
|
||||
begin
|
||||
return Left = Right;
|
||||
end Equivalent_Key;
|
||||
|
||||
function Hash_Func(Key : Unbounded_String) return Ada.Containers.Hash_Type is
|
||||
begin
|
||||
return Ada.Strings.Hash(To_String(Key));
|
||||
end Hash_Func;
|
||||
|
||||
package My_Hash is new Ada.Containers.Hashed_Maps(Key_Type => Unbounded_String,
|
||||
Element_Type => Unbounded_String,
|
||||
Hash => Hash_Func,
|
||||
Equivalent_Keys => Equivalent_Key);
|
||||
|
||||
type String_Array is array(Positive range <>) of Unbounded_String;
|
||||
|
||||
Hash : My_Hash.Map;
|
||||
Key_List : String_Array := (To_Unbounded_String("foo"),
|
||||
To_Unbounded_String("bar"),
|
||||
To_Unbounded_String("val"));
|
||||
|
||||
Element_List : String_Array := (To_Unbounded_String("little"),
|
||||
To_Unbounded_String("miss"),
|
||||
To_Unbounded_String("muffet"));
|
||||
|
||||
begin
|
||||
for I in Key_List'range loop
|
||||
Hash.Insert(Key => (Key_List(I)),
|
||||
New_Item => (Element_List(I)));
|
||||
end loop;
|
||||
for I in Key_List'range loop
|
||||
Ada.Text_Io.Put_Line(To_String(Key_List(I)) & " => " &
|
||||
To_String(Hash.Element(Key_List(I))));
|
||||
end loop;
|
||||
|
||||
end Hash_Map_Test;
|
||||
Loading…
Add table
Add a link
Reference in a new issue