-- $Date: 2004/01/27 12:02:11 $
-- $Revision: 1.4 $
-- $Author: jcrocholl $

with Ada.Text_IO;

with Primes; use Primes;
with Messages; use Messages;

package body String_String_Hash_Tables is

   ------------------------------
   -- Storing and retrieving data
   ------------------------------

   -- Check for available space in the table, grow if necessary, then
   -- insert the key item pair into the table.
   -- Raises Key_Exists if the key is already in use.
   procedure Put
     (This : in out Hash_Table_Access-- Add pair to this hash table.
      Key  : in String;                -- Create this key.
      Item : in String)                -- Associate this item.
   is
      Pair : Inner_Tables.Pair_Access := new Inner_Tables.Pair;
   begin
      To_String_Access(Key, Pair.Key);
      To_String_Access(Item, Pair.Item);
      Inner_Tables.Put(This, Pair);
   end Put;
   pragma Inline(Put);


   -- Retrieve an item from the table.
   -- Raises Key_Not_Found if the key is not in the table.
   function Get
     (This : access Hash_Table-- Get value from this hash table.
      Key  : in String)         -- Look up this key.
     return String is           -- The item that was found.
   begin
      return Get_Item(This, Get_Index(This, Key));
   end Get;
   pragma Inline(Get);

   -----------------
   -- Indexed access
   -----------------

   -- Get the index of a given key.
   function Get_Index
     (This : access Hash_Table-- Get key from this hash table.
      Key  : in String)         -- Iteration pointer to the current field.
     return Positive            -- The index of the requested key.
   is
      Temp  : String_Access;
      Index : Positive;
   begin
      To_String_Access(Key, Temp);
      Index := Inner_Tables.Get_Index(This, Temp);
      Free(Temp);
      return Index;
   end Get_Index;
   pragma Inline(Get_Index);

   -- Get the key at a given index position.
   function Get_Key
     (This  : access Hash_Table-- Get key from this hash table.
      Index : in Positive)       -- Iteration pointer to the current field.
     return String is            -- The requested key.
   begin
      return To_String(Inner_Tables.Get_Key(This, Index));
   end Get_Key;
   pragma Inline(Get_Key);

   -- Get the item at a given index position.
   function Get_Item
     (This  : access Hash_Table-- Get item from this hash table.
      Index : in Positive)       -- Iteration pointer to the current field.
     return String is            -- The requested item.
   begin
      return To_String(Inner_Tables.Get_Item(This, Index));
   end Get_Item;
   pragma Inline(Get_Key);

end String_String_Hash_Tables;