minimal_containers_1.0.0_592661c6/test/src/test_maps.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
with Ada.Containers;
with Minimal_Containers.Bounded_Hashed_Maps;
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Maps is
   function Hash (Key : Natural) return Ada.Containers.Hash_Type
   is (Ada.Containers.Hash_Type (Key));
   package My_Maps is new Minimal_Containers.Bounded_Hashed_Maps
     (Key_Type     => Natural,
      Element_Type => Integer,
      Hash         => Hash);
   use My_Maps;
   M : Map (Capacity => 6, Modulus => 0);
   C : Cursor;
   procedure Report (Message : String) is
   begin
      Put_Line ("Report for " & Message);
      for K of M loop
         Put_Line (K'Image & " => " & Element (M, K)'Image);
      end loop;
      Put_Line ("--------");
      New_Line;
   end Report;
begin
   Report ("initial");
   for J in 0 .. 3 loop
      Insert (Container => M, Key => J, New_Item => -J);
   end loop;
   Report ("setup");
   Insert (Container => M, Key => 42, New_Item => -42);
   Report ("added another");
   C := Find (M, 3);
   Delete (M, Key => 0);
   Delete (M, Position => C);
   Report ("deleted 0 and 3");
end Test_Maps;