with String_Integer_Maps;  use String_Integer_Maps;
with Ada.Command_Line;
with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;
with To_Key;

procedure Test_Hash is

   M1, M2 : Map;
   N : Integer;

begin

   if Ada.Command_Line.Argument_Count = 0 then
      N := 10;
   else
      declare
         Last : Natural;
      begin
         Get (Ada.Command_Line.Argument (1), N, Last);
      end;
   end if;

   Reserve_Capacity (M1, Capacity => 10000);

   Put_Line ("start");

   for I in Integer range 0 .. 9999 loop
      Insert (M1, "foo_" & To_Key (I, Base => 10), I);
   end loop;

   Put ("m1[foo_1]=");
   Put (Element (M1, "foo_1"), Width => 0);
   New_Line;

   Put ("m1[foo_9999]=");
   Put (Element (M1, "foo_9999"), Width => 0);
   New_Line;

   Reserve_Capacity (M2, Capacity => Length (M1));

   for I in Integer range 1 .. N loop

      Put (I, Width => 0); New_Line;

      declare
         procedure Process (C1 : Cursor) is
            C2 : Cursor;
            B : Boolean;
         begin
            Insert (M2, Key (C1), 0, C2, B);

            declare
               procedure Increment
                 (K : in String;
                  I2 : in out Integer) is
               begin
                  I2 := I2 + Element (C1);
               end;
            begin
               Update_Element (C2, Increment'Access);
            end;
         end Process;
      begin
         Iterate (M1, Process'Access);
      end;

   end loop;

   Put ("m2[foo_1]=");
   Put (Element (M2, "foo_1"), Width => 0);
   New_Line;

   Put ("m2[foo_9999]=");
   Put (Element (M2, "foo_9999"), Width => 0);
   New_Line;

end Test_Hash;
